code_junkie

SharePoint and Office Open XML interaction question

Nov 12th, 2011
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. Stream fs = mySPFile.OpenBinaryStream();
  2.  
  3. using (WordprocessingDocument ooxmlDoc = WordprocessingDocument.Open(fs, true))
  4. {
  5.  
  6. MainDocumentPart mainPart = wordDoc.MainDocumentPart;
  7. XmlDocument xmlMainDocument = new XmlDocument();
  8. xmlMainDocument.Load(mainPart.GetStream());
  9.  
  10. // change the contents of the ooxmlDoc / xmlMainDocument
  11.  
  12. Stream stream = mainPart.GetStream(FileMode.Open, FileAccess.ReadWrite);
  13. xmlMainDocument.Save(stream);
  14. // the stream should not be longer than the DocumentPart
  15. stream.SetLength(stream.Position);
  16. }
  17. mySPFile.SaveBinary(fs);
  18. fs.Dispose();
Add Comment
Please, Sign In to add comment