Working with DOCX


https://www.nevron.com/Forum/Topic13032.aspx
Print Topic | Close Window

By Rob Panosh - 4 Years Ago
Hi,
 We would like to store a docx in our database as a string.  Then load back into the RichText control.  We are having trouble.
Here is our public property on our user control to get/set value


It will save to the database but when we try to reassign your control it asks if we would like to save the value.  If I select "Yes" to save the document open blank.  I have saved the value for Me.BusinessObect.Body and attached.





Please advise ... 

Thanks, Rob


By Rob Panosh - 4 Years Ago
Hi,

Haven't heard response?  Any ideas we need to get this sorted out.

Thanks,
Rob
By Nevron Support - 4 Years Ago
Hi Rob,

Apologies for the delayed response, we must have missed the original post.

UTF8 character encoding is not a good way to encode a byte array for database storage roundtrip. It may result in information loss particularly in the area of Unicode surrogate characters (0xD800 to 0xDBFF) as some byte sequences may not be a valid unicode surrogate character sequence. We would recommend you to use base64 character encoding instead as it will not result in information loss. We tested with the following code and it was working properly:

  string docxText = string.Empty;

   private void button1_Click(object sender, EventArgs e)
   {
    {
      MemoryStream stream = new MemoryStream();
      m_TextControl.View.SaveToStream(stream, new Nevron.Nov.Text.Formats.NDocxTextFormat());
   
      docxText = Convert.ToBase64String(stream.ToArray());
    }
   }

   private void button2_Click(object sender, EventArgs e)
   {
    {
      MemoryStream stream = new MemoryStream(Convert.FromBase64String(docxText));
      m_TextControl.View.LoadFromStream(stream, new Nevron.Nov.Text.Formats.NDocxTextFormat());
    }
   }

We hope this helps - let us know if you have any questions or meet any problems.