我有这个功能,我将文件上传到Sharepoint 2013文档库。我希望能够检索新创建的文档库条目的Id。
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();
}
答案 0 :(得分:3)
File.ListItemAllFields property获取一个值,该值指定与该文件对应的列表项的列表项字段值。
示例:
context.Load(uploadFile,f => f.ListItemAllFields) ;
context.ExecuteQuery();
//Print List Item Id
Console.WriteLine("List Item Id: {0}", uploadFile.ListItemAllFields.Id);