0

I am trying to do a simple operation “Delete file from document library using CSOM” As i have only the Relative path “http://hostname/subsite/subsite/doclibname/sample.docx

I used below code to get the File object and then delete it.

Microsoft.SharePoint.Client.File file = clientContext.Web.GetFileByServerRelativeUrl(relativePath); clientContext.Load(file);
file.DeleteObject();
clientContext.ExecuteQuery();

The code executes without errors. However the file doesn’t get deleted.

Googled for it. Getting solutions of using LibraryName. However in real scenario i won’t be getting the document library name. I will be just getting URL.

Kindly advise.

(Visited 533 times, 1 visits today)
Beau Cameron Selected answer as best April 20, 2018
Add a Comment