Returning Guid of newly created item in Sharepoint Library
-
15-04-2021 - |
سؤال
I am using the method
File.SaveBinaryDirect
in Microsoft.SharePoint.Client to insert new documents in a Sharepoint Library. just wondering what is the most effective way of getting the Guids of those new records.
المحلول
Well, you've just saved the file to a particular URL - get the File by that URL, and then use the ListItemAllFields property to get the ListItem that would contain those IDs
From here:
var FileSrvRelUrl = "/sub/doclib/Folder/File.doc";
using (var fileStream = new MemoryStream(new byte[100]))
{
Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, FileSrvRelUrl, fileStream, false);
}
var web = clientContext.Web;
var f = web.GetFileByServerRelativeUrl(FileSrvRelUrl);
var item = f.ListItemAllFields;
item["SomeField"] = "Value";
item.Update();
clientContext.Load(item, i=>i.Id);
clientContext.ExecuteQuery();
لا تنتمي إلى StackOverflow