1

Open XML SDK 2.5 を使用して、SharePoint 2013 で単純な docx ファイルを生成しようとしています。

私の関数は、SharePoint ライブラリに docx ファイルを正常に生成しますが、それを開こうとすると、空であるか破損しています。私はすでに多くのことを試し、ここや Web で見つけたさまざまなテクニックを使用しました。

 protected void generateDoc(string docName)
    {
        SPWeb spWeb = SPContext.Current.Web;

        spWeb.AllowUnsafeUpdates = true;
        spWeb.Lists.IncludeRootFolder = true;

        SPList docLib = spWeb.Lists["test"];
        string fileUrl = Microsoft.SharePoint.Utilities.SPUtility.GetFullUrl(SPContext.Current.Site, "/test/" + docName);

        SPSecurity.CodeToRunElevated elevatedSubmit = new SPSecurity.CodeToRunElevated(delegate
        {
            // MediaStream erstellen
            using (MemoryStream ms = new MemoryStream())
            {
                // Create a Wordprocessing document.
                using (WordprocessingDocument package = WordprocessingDocument.Create(ms, WordprocessingDocumentType.Document))
                {
                    // Add a new main document part. 
                    package.AddMainDocumentPart();
                    // Create the Document DOM. 
                    package.MainDocumentPart.Document = new Document();
                    package.MainDocumentPart.Document.Append(new Body());
                    package.MainDocumentPart.Document.Append(
                           new Paragraph(
                             new Run(
                               new Text("TEST"))));

                    ms.Position = 0;
                    byte[] content = ms.ToArray();
                    package.MainDocumentPart.Document.Save();

                    SPFile file = docLib.RootFolder.Files.Add(fileUrl, ms, true);
                    file.Update();
                }
            }
        });
        SPSecurity.RunWithElevatedPrivileges(elevatedSubmit);
    }

どなたかヒントを頂ければ幸いです。

前もって感謝します!!

4

2 に答える 2