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.
source to share
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();
source to share
btw I found that all 10 web clips in this series were very good.
source to share