Получение идентификатора из загруженного файла в Sharepoint 2013 DocumentLibrary

У меня есть эта функция, когда я загружаю файл в библиотеку документов Sharepoint 2013. Я хочу иметь возможность получить вновь созданный идентификатор записи библиотеки документов.

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

person Mehmet Rasim İnceoğlu    schedule 05.03.2014    source источник


Ответы (1)


File.ListItemAllFields свойство получает значение, указывающее значения поля элемента списка для элемента списка, соответствующего файлу.

Пример:

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