0

我的问题是我将有 1..n 个文件合并到一个文件中。我在 Sharepoint 服务器上有一个目标 SPFile。我已经编写了一个基于有关 OpenXML 的网站的方法,它运行时没有错误,但在我查看它时最终是空白的。

这是方法

    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();
        }
    }    

同样,它只是返回一个空白文档,但也不会损坏它。

谢谢。

蒂姆丹尼尔斯

4

1 回答 1

0

在玩弄它之后我发现了问题我需要在“maindocument.Documents.Save()”行之后将以下三行添加到方法中

targetDoc.Close();
targetStream.Flush();
target.SaveBinary(targetStream);
于 2013-06-14T22:09:00.213 回答