方法将SPFile合并到现有SPFile中
我的问题是,我将有1..n个文件合并到一个文件中。我在Sharepoint服务器上有一个目标SPF文件。我已经写了一个基于OpenXML的网站的方法,它运行时没有错误,但当我查看它时,结果是空白的 这里是方法方法将SPFile合并到现有SPFile中,file,sharepoint,merge,File,Sharepoint,Merge,我的问题是,我将有1..n个文件合并到一个文件中。我在Sharepoint服务器上有一个目标SPF文件。我已经写了一个基于OpenXML的网站的方法,它运行时没有错误,但当我查看它时,结果是空白的 这里是方法 private void InsertSPFileInto(SPFile target, SPFile source, int index) { Stream targetStream = target.OpenBinaryStream();
private void InsertSPFileInto(SPFile target, SPFile source, int index)
{
Stream targetStream = target.OpenBinaryStream();
using (WordprocessingDocument myDoc = WordprocessingDocument.Open(targetStream, true))
{
string altChunkId = "AltChunkId" + index.ToString();
MainDocumentPart mainPart = myDoc.MainDocumentPart;
AlternativeFormatImportPart chunk =
mainPart.AddAlternativeFormatImportPart(
AlternativeFormatImportPartType.WordprocessingML,
altChunkId);
Stream sourceStream = source.OpenBinaryStream();
chunk.FeedData(sourceStream);
AltChunk altChunk = new AltChunk();
altChunk.Id = altChunkId;
mainPart.Document
.Body
.InsertAfter(altChunk,mainPart.Document.Body.LastChild);
mainPart.Document.Save();
}
}
同样,它只返回一个空白文档,但也不会损坏它
谢谢
蒂姆·丹尼尔斯(Tim Daniels)在使用它之后,我发现了一个问题,我需要在方法的“maindocument.Documents.Save()行之后添加以下三行
targetDoc.Close();
targetStream.Flush();
target.SaveBinary(targetStream);