如何将文件上传到Sharepoint中的文档库? [英] How do you upload a file to a document library in sharepoint?
本文介绍了如何将文件上传到Sharepoint中的文档库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您如何以编程方式将文件上传到sharepoint中的文档库中?
How do you programmatically upload a file to a document library in sharepoint?
我目前正在使用C#制作Windows应用程序,该应用程序会将文档添加到文档库列表中。
I am currently making a Windows application using C# that will add documents to a document library list.
推荐答案
您可以使用对象模型或 SharePoint Web服务。
You can upload documents to SharePoint libraries using the Object Model or SharePoint Webservices.
使用对象模型上传:
String fileToUpload = @"C:\YourFile.txt";
String sharePointSite = "http://yoursite.com/sites/Research/";
String documentLibraryName = "Shared Documents";
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();
}
}
这篇关于如何将文件上传到Sharepoint中的文档库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文