We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Converting RichTextBoxAdv document to .doc is saving as blank pages?

Thread ID:

Created:

Updated:

Platform:

Replies:

115460 Jan 17,2014 10:38 AM Jan 21,2014 07:17 AM Silverlight 3
loading
Tags: DocIO
Michael Velasquez
Asked On January 17, 2014 10:38 AM

I'm using a RichTextBoxAdv to display .doc/.docx files for editing within my Silverlight application. After manipulation is complete, I'm attempting to export that edited copy back to my file system (or server).
In debug mode, when stepping through the code I'm successfully converting the document into a MemoryStream object. Or so it seems.
However, when I attempt to extract the byte array of the object from that memory stream and upload that byte array as a document to the server it ends up being a blank .doc/.docx document of several blank pages.

Am I doing something wrong in the conversion? Here's my code:

 wordDoc = xmlDocContainer.FindName("wordDocRichTextBox") as Syncfusion.Windows.Tools.Controls.RichTextBoxAdv;
                DocxExporting.ConvertToDocument(wordDoc.Document, stream, "." + extension);

Then I'm extracting the byte array for future upload to the server and holding it in memory here:

 private static bool OpenFile(Stream stream, string ext)
        {
            bool result = false;
            try
            {
                App.FilesToUpload = new List<KTFileUpload>();
                App.FilesToUpload.Add(new KTFileUpload() { File = new byte[stream.Length], Ext = ext.TrimStart('.') });
                int numBytesToRead = (int)stream.Length;
                int numBytesRead = 0;
                while (numBytesToRead > 0)
                {
                    // Read may return anything from 0 to numBytesToRead.
                    int n = stream.Read(App.FilesToUpload[0].File, numBytesRead, numBytesToRead);

                    // Break when the end of the file is reached.
                    if (n == 0)
                        break;

                    numBytesRead += n;
                    numBytesToRead -= n;
                }
                result = true;
            }
            catch(Exception ex) //once we setup logging capability grab the exception.
            {
                App.ShowErrorDialog("Unable to open file. File may be locked or too large.");
            }

            return result;
        }

Michael Velasquez
Replied On January 17, 2014 11:13 AM

Just some quick further information:

When I finish the OpenFile method, the byte array that I've built from the stream is 49152 positions in length, yet every position is empty with a value of "0".

Michael Velasquez
Replied On January 17, 2014 12:27 PM

It actually looks like I needed an FileStream rather than simply a MemoryStream.

Thanks.

Sathish K [Syncfusion]
Replied On January 21, 2014 07:17 AM

Hi Michael,

 

Thank you for your interest in Syncfusion products.

 

When the code “DocxExporting.ConvertToDocument(wordDoc.Document, stream, "." + extension);” gets executed, the file pointer is moved to the end of file location. So while trying to read the stream data it starts reading from end of file location. So only you are unable to read the stream and get the value 0.

To overcome this problem just set stream position to 0 using the code, “stream.Position = 0”. Here is the modified code snippet.

 

while (numBytesToRead > 0)
{

//Modified code.

stream.Position = 0;
// Read may return anything from 0 to numBytesToRead.
int n = stream.Read(App.FilesToUpload[0].File, numBytesRead, numBytesToRead);
//Your remaining code

}

 

For your reference, we have prepared a sample to illustrate the same. Please find the attached sample and let us know if this helps you.

 

Please let us know if you need any further assistance.

 

Regards,

Sathish



Sample_f065af06.zip

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;