Interoperability issues with SharePoint and Office Open XML

I was disappointed with this all weekend plus a day or two, so any help would be greatly appreciated.

I am trying to write a program that can programmatically navigate to a SharePoint 2007 document library, open a file, change the contents of the file, and then check in the file. I got everything but the last part of this. The reason Office Open XML is because I open a document and modify it is through the Office Open XML SDK. My question is, how do I get it from the document back to the library?

The problem, as I see it, is that there is no save function in the WordprocessingDocument object. This prevents me from saving it in the SPFile SaveBinary function.

+1


source to share


2 answers


You must use a stream to write the modified OOXML to the SPFile. Hope this example helps!



Stream fs = mySPFile.OpenBinaryStream();

using (WordprocessingDocument ooxmlDoc = WordprocessingDocument.Open(fs, true))
{

    MainDocumentPart mainPart = wordDoc.MainDocumentPart;
    XmlDocument xmlMainDocument = new XmlDocument();
    xmlMainDocument.Load(mainPart.GetStream());

   // change the contents of the ooxmlDoc / xmlMainDocument

   Stream stream = mainPart.GetStream(FileMode.Open, FileAccess.ReadWrite);
   xmlMainDocument.Save(stream);
   // the stream should not be longer than the DocumentPart
   stream.SetLength(stream.Position); 
}
mySPFile.SaveBinary(fs);
fs.Dispose();

      

+2


source


Yesterday I saw a live stream from Andrew Connell where he opened a document from a document library, added a watermark, and saved the file again. Looks like you should take a look at this broadcast: https://msevents.microsoft.com/CUI/WebCastRegistrationConfirmation.aspx?culture=en-US&RegistrationID=1299758384&Validate=false


btw I found that all 10 web clips in this series were very good.

0


source







All Articles