To ensure that printed letters can be restored, You need to record the content of Word letters every time you print a letter. SQLServer can only record the text content of a letter. How can I store the page layout, font style, and other content of a letter? At this time, Mongodb debuted, because the document structure of MongoDB is BJSON (BJS
To ensure that printed letters can be restored, You need to record the content of Word letters every time you print a letter. SQL Server can only record the text content of a letter. How can I store the page layout, font style, and other content of a letter? At this time, Mongodb debuted, because the document structure of MongoDB is BJSON (BJS
To ensure that printed letters can be restored, You need to record the content of Word letters every time you print a letter.
SQL Server can only record the text content of a letter. How can I store the page layout, font format, and other content of a letter? At this time, Mongodb debuted. Because MongoDB's document structure is in BJSON format (BJSON Full name: Binary JSON), BJSON itself supports storing data in Binary format, therefore, the binary data of the file can be directly stored in the document structure of MongoDB. The file is then retrieved in binary format, so that the file can be saved lossless.
Below is what I have verified. I will store the Word to Mongo and then read the Word code from Mongo. I will share with you here.
Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. windows. forms; using System. IO; using MongoDB. bson; using MongoDB. driver; namespace Mongodb {public partial class Form1: Form {public Form1 () {InitializeComponent (); Init () ;}// database connection string const string strconn = "mongodb: // 127.0.0.1: 27017 "; // database name const string dbName =" test "; Login server; login database db; void Init () {// create database link server = MongoDB. driver. login server. create (strconn); // obtain database db = server. getDatabase (dbName);} private void btnSave_Click (object sender, EventArgs e) {SaveDocToMongo (@ "d: \ quwenzhe.docx");} private void btnShow_Click (object sender, EventArgs e) {GetDocFromMongo (@ "E: \ newquwenzhe.doc ");}////// Save the Word to Mongo //////File name to be savedPrivate void SaveDocToMongo (string filename) {byte [] byteDoc = File. readAllBytes (filename); BsonDocument doc = new BsonDocument (); doc ["id"] = "1"; doc ["content"] = byteDoc; your collection col = db. getCollection ("doc"); col. save (doc );}////// Save the Word in Mongo to the local device //////File name saved to the local devicePrivate void GetDocFromMongo (string filename) {your collection col = db. getCollection ("doc"); var query = new QueryDocument {"id", "1" }}; var result = col. findAs
(Query); byte [] buff = (byte []) (BsonDocument) result. toList () [0]). getValue ("content"); FileStream fs; FileInfo fi = new FileInfo (filename); fs = fi. openWrite (); fs. write (buff, 0, buff. length); fs. close ();}}}
After the storage operation is completed, you can view the binary data in the stored Vue, as shown in:
: Http://pan.baidu.com/s/1pj5dter.
Okay, it's not too early. I have to take a nap and prepare for the soft exam in the afternoon. Thank you for watching it.