【发布时间】:2014-04-27 20:03:48
【问题描述】:
我有一个 Web 部件,用户可以在上面写下他们的信息。我需要做的是在用户单击“保存”按钮后将这些信息以 PDF 格式保存到共享点文档库。
我正在使用 itextsharp,到目前为止我所做的是在 SP 服务器 c:\ 驱动器中创建 PDF 并将其上传到 sarepoint 文档库。但我想做的是不在 c:\ 驱动器中创建文档。谢谢你
//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();
}
}
【问题讨论】:
标签: c# asp.net sharepoint