Domanda

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();
    }
È stato utile?

Soluzione

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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top