我使用以下功能将文件上传到sharepoint 2010库,对我来说很好用
void upload()
{
ClientContext clientContext = new ClientContext("http://dev.sp-projects.com:880");
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
string filePath = @"C:\SP\sp.txt";
string filename = "sp.txt";
using (FileStream fs = new FileStream(filePath, FileMode.Open))
{
Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, "/folder1/folder2/" + filename, fs, true);
}
}
但是,当我使用以下功能检查同一文件时,出现错误消息“找不到文件”
void CheckInOnly()
{
ClientContext clientContext = new ClientContext("http://dev.sp-projects.com:880");
Microsoft.SharePoint.Client.File fl = clientContext.Web.GetFileByServerRelativeUrl("/folder1/folder2/sp.txt");
clientContext.Load(fl);
clientContext.ExecuteQuery()
fl.CheckIn("checkin", CheckinType.MajorCheckIn);
}