问题
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