从上传的文件中获取 ID 到 Sharepoint 2013 DocumentLibrary [英] Getting Id from uploaded file to Sharepoint 2013 DocumentLibrary

查看:50
本文介绍了从上传的文件中获取 ID 到 Sharepoint 2013 DocumentLibrary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个功能,可以将文件上传到 Sharepoint 2013 文档库.我希望能够检索文档库条目的新创建的 ID.

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

推荐答案

File.ListItemAllFields 属性 获取一个值,该值指定与文件对应的列表项的列表项字段值.

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

示例:

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

这篇关于从上传的文件中获取 ID 到 Sharepoint 2013 DocumentLibrary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆