Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将web表单转换为pdf并上载到sharepoint文档库?_C#_Asp.net_Sharepoint - Fatal编程技术网

C# 如何将web表单转换为pdf并上载到sharepoint文档库?

C# 如何将web表单转换为pdf并上载到sharepoint文档库?,c#,asp.net,sharepoint,C#,Asp.net,Sharepoint,我有一个web部件,用户可以在上面写信息。我需要做的是在用户单击“保存”按钮后将这些信息以PDF格式保存到sharepoint文档库 我正在使用itextsharp,到目前为止我所做的是在SP server c:\drive中创建PDF并将其上载到sarepoint文档库。但我想做的是不在c:\drive中创建文档。多谢各位 //creates document in c:// drive Document document = new Document(); PdfWr

我有一个web部件,用户可以在上面写信息。我需要做的是在用户单击“保存”按钮后将这些信息以PDF格式保存到sharepoint文档库

我正在使用itextsharp,到目前为止我所做的是在SP server c:\drive中创建PDF并将其上载到sarepoint文档库。但我想做的是不在c:\drive中创建文档。多谢各位

//creates document in c:// drive
Document document = new Document();
            PdfWriter.GetInstance(document, new FileStream(Page.Request.PhysicalApplicationPath + "\\MySamplePDF.pdf", FileMode.Create));
            document.Open();
            iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
            hw.Parse(new StringReader(content));
            document.Close();

//then uploads to sharepoint librart
            String fileToUpload = Page.Request.PhysicalApplicationPath +"\\MySamplePDF.pdf";
            String sharePointSite = "http://testportal/";
            String documentLibraryName = "mydefdoclibi";

            using (SPSite oSite = new SPSite(sharePointSite))
            {
                using (SPWeb oWeb = oSite.OpenWeb())
                {
                    if (!System.IO.File.Exists(fileToUpload))
                        throw new FileNotFoundException("File not found.", fileToUpload);

                    SPFolder myLibrary = oWeb.Folders[documentLibraryName];

                    // Prepare to upload
                    Boolean replaceExistingFiles = true;
                    String fileName = System.IO.Path.GetFileName(fileToUpload);
                    FileStream fileStream = File.OpenRead(fileToUpload);

                    // Upload document
                    SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles);

                    // Commit 
                    myLibrary.Update();
                }
            }

因此,使用MemoryStream而不是写入文件

using(MemoryStream ms = new MemoryStream())
{
    PdfWriter.GetInstance(document, ms, FileMode.Create));

    ...
    ms.Position = 0;
    SPFile spfile = myLibrary.Files.Add(fileName, ms, replaceExistingFiles);
...
}