Thursday, January 7, 2021

Get file url from SharePoint by name

 List docs = web.Lists.GetByTitle("DOCUMENTS");

Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);

clientContext.ExecuteQuery();


clientContext.Load(uploadFile.ListItemAllFields, item => item["EncodedAbsUrl"]);

clientContext.ExecuteQuery();


var fileUrl = uploadFile.ListItemAllFields["EncodedAbsUrl"].ToString();


string link = ctx.Web.CreateAnonymousLinkForDocument(fileUrl, ExternalSharingDocumentOption.View);


string linkwithExpiration = ctx.Web.CreateAnonymousLinkWithExpirationForDocument(fileUrl, ExternalSharingDocumentOption.Edit, DateTime.Now.AddMonths(1));


SharingResult result = ctx.Web.ShareDocument(fileUrl, "reven@peakfinders.com", ExternalSharingDocumentOption.View, true, "Documents shared Sucessfully");


No comments:

Post a Comment