Quantcast
Channel: Open XML Format SDK forum
Viewing all articles
Browse latest Browse all 1288

MemoryStream and WordprocessingDocument

$
0
0

Hi Everyone, 

 I have a problem when using the WordProcessingDocument object together with a MemoryStream object. 

 My code is the following. 

MemoryStream stream = new MemoryStream(loanDocumentViewModel.DocumentContent);

            //using (MemoryStream stream = new MemoryStream(data)) //;MemoryStream ms = new MemoryStream(dc.DocumentContent))
            //{
            using (WordprocessingDocument doc = WordprocessingDocument.Open(stream, true))
            //using (WordprocessingDocument doc = WordprocessingDocument.Open(@"Documents\OtherDocuments\copy.docx", true))
            {

              DocumentSettingsPart docSett = doc.MainDocumentPart.DocumentSettingsPart;
                docSett.RootElement.Append(new DocumentProtection { Edit = DocumentProtectionValues.ReadOnly });
                docSett.RootElement.Save();

                doc.MainDocumentPart.Document.Save();
            }

The dc.DocumentContent is a Array readed from a Database. 

When I save my object into the Database again and open it. 

   Word is telling me that the file is corrupt, but It can be opened. 

Any clues on what wrong with the code?

I have tried to do the same operation, with a plain file and that works perfectly. 

Best Regards

  Lars 


Viewing all articles
Browse latest Browse all 1288

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>