Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Sep 15, 2017 9:43 am

Is it possible to save the content of content controls with all the formatting intact to sql server in varbinary column? So later I can retrieve back and compose a new doc with all the formatting still intact.

Here's my snippet:
StructureDocumentTag sdt = node as StructureDocumentTag;
if (sdt.SDTProperties.Tag==tag) {
//i have located my content control here
foreach (DocumentObject item in sdt.ChildObjects) {
if (item is Paragraph) {
//i can read the text of para
Paragraph para = item as Paragraph;
}
}
I have tried to serialize sdt.ChildObjects/ para via binaryFormatter.Serialize/ xmlSerializer.Serialize, both cause System.NullReferenceException.
Please kindly guide me, thank you.

chtui
 
Posts: 5
Joined: Thu Sep 07, 2017 8:34 am

Fri Sep 15, 2017 10:15 am

Hi,

Thanks for your inquiry.
Could you please share your sample file and code with us(support@e-iceblue.com) so that we can have a better
investigation?

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Fri Sep 15, 2017 11:11 am

I have found the cause which is the spire doc not marked as serializable, is there alternative?
Code: Select all
private void ContentToByte() {
         string fileName = "Content2.docx";
         string path = System.Web.HttpRuntime.AppDomainAppPath + fileName;
         Document doc = new Document(path, FileFormat.Docx2013);
         //byte[] bin = ReadBytes(doc.Clone()); //is not marked as serializable
         string tag = "rtcc1";
         foreach (Section section in doc.Sections) {
            foreach (Body body in section.ChildObjects) {
               foreach (DocumentObject node in body.ChildObjects) {
                  if (node is StructureDocumentTag) {
                     StructureDocumentTag sdt = node as StructureDocumentTag;
                     //byte[] bin = ReadBytes(sdt.Clone()); //is not marked as serializable
                     //byte[] bin = ReadBytes(sdt); //is not marked as serializable
                     if (sdt.SDTProperties.Tag == tag) {
                        foreach (DocumentObject item in sdt.ChildObjects) {
                           if (item is Paragraph) {
                              Paragraph para = item as Paragraph;
                              //byte[] bin = ReadBytes(para.Clone()); //is not marked as serializable
                           }
                        }
                     }
                  }
               }
            }
         }
      }
      static byte[] ReadBytes(object content) {
         MemoryStream ms = new MemoryStream();
         BinaryFormatter binaryFormatter = new BinaryFormatter();
         binaryFormatter.Serialize(ms, content);
         return ms.GetBuffer();  //ms.ToArray();
      }

chtui
 
Posts: 5
Joined: Thu Sep 07, 2017 8:34 am

Mon Sep 18, 2017 6:41 am

Hello,

Thanks for your response. Sorry that at present it doesn't support to be serializable, and there is no alternative.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.Doc