正在从上载到Sharepoint 2013 DocumentLibrary的文件获取Id
我有此功能,可以将文件上载到Sharepoint 2013文档库中。我希望能够检索新创建的文档库条目Id正在从上载到Sharepoint 2013 DocumentLibrary的文件获取Id,sharepoint,csom,Sharepoint,Csom,我有此功能,可以将文件上载到Sharepoint 2013文档库中。我希望能够检索新创建的文档库条目Id public void UploadFileToSharePoint(string file) { ClientContext context = new ClientContext("http://test-sp01"); Web web = context.Web; FileCreationInformation newFile
public void UploadFileToSharePoint(string file)
{
ClientContext context = new ClientContext("http://test-sp01");
Web web = context.Web;
FileCreationInformation newFile = new FileCreationInformation();
newFile.Content = System.IO.File.ReadAllBytes(file);
newFile.Url = System.IO.Path.GetFileName(file);
List docs = web.Lists.GetByTitle("TestDocumentLibrary");
Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);
context.Load(uploadFile);
context.ExecuteQuery();
}
获取一个值,该值指定与文件对应的列表项的列表项字段值
例如:
context.Load(uploadFile,f => f.ListItemAllFields) ;
context.ExecuteQuery();
//Print List Item Id
Console.WriteLine("List Item Id: {0}", uploadFile.ListItemAllFields.Id);