1

我整个周末都为此感到沮丧,再加上一两天,所以任何帮助都将不胜感激。

我正在尝试编写一个程序,该程序可以以编程方式进入 SharePoint 2007 文档库,打开文件,更改文件内容,然后将文件放回原处。除了最后一部分之外,我已经完成了所有工作。涉及 Office Open XML 的原因是我通过 Office Open XML SDK 打开和修改文档的方式。我的问题是:如何将它从文档中取回图书馆?

我看到的问题是 WordprocessingDocument 对象本身没有保存功能。这使我无法将其保存到 SPFile 的 SaveBinary 函数中。

4

2 回答 2

2

您应该使用流将更改的 OOXML 写回 SPFile。我希望这个例子有帮助!

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();
于 2008-11-24T14:17:26.390 回答
0

昨天我看到了 Andrew Connell 的网络广播,他从文档库中打开了一个文档,添加了水印并再次保存了文件。听起来您确实应该看一下该网络广播: https ://msevents.microsoft.com/CUI/WebCastRegistrationConfirmation.aspx?culture=en-US&RegistrationID=1299758384&Validate=false

顺便说一句,我发现该系列中的所有 10 个网络广播都非常好。

于 2008-11-23T23:16:45.447 回答