Getting Id from uploaded file to Sharepoint 2013 DocumentLibrary

*爱你&永不变心* 提交于 2019-12-24 03:00:32

问题


I have this function where I upload a file into a Sharepoint 2013 Document Library. I want to be able to retrieve the newly created Id of the Document Library entry.

 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();
    }

回答1:


File.ListItemAllFields property gets a value that specifies the list item field values for the list item corresponding to the file.

Example:

context.Load(uploadFile,f => f.ListItemAllFields) ;
context.ExecuteQuery();
//Print List Item Id
Console.WriteLine("List Item Id: {0}", uploadFile.ListItemAllFields.Id);


来源:https://stackoverflow.com/questions/22201720/getting-id-from-uploaded-file-to-sharepoint-2013-documentlibrary

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!