0

I have problem with sharepoint when I try to get all file in a specific url. I've try get files in url

https://mycompany.sharepoint.com/

It's work, but when want to get files in url

https://mycompany.sharepoint.com/sites/Processing/Shared%20Documents/Forms/AllItems.aspx?viewid=b59c189a-26e1-42ff-b0b8-0e5aefc93734&id=%2Fsites%2FProcessing%2FShared%20Documents%2FGeneral%2FApp2020

It returns error Microsoft.SharePoint.Client.ServerException: File Not Found.

This is the first time I work with sharepoint. I'm look forward to receive your help. Many thanks.

Here is my code:

var targetSiteURL = new Uri("https://mycompany.sharepoint.com/sites/Processing/");
ClientContext cxt = new ClientContext(targetSiteURL.GetLeftPart(UriPartial.Authority));
cxt.Credentials = new SharePointOnlineCredentials(login, securePassword);
                    
var list = cxt.Web.GetList("/Shared%20Documents/Forms/AllItems.aspx?viewid=b59c189a-26e1-42ff-b0b8-0e5aefc93734&id=%2Fsites%2FProcessing%2FShared%20Documents%2FGeneral%2FApp2020");

var listItems = list.GetItems(new CamlQuery());
cxt.Load(listItems,
items => items.Include(
item => item.File));
cxt.ExecuteQuery();                    
this.lblMessage.Text = listItems.First().File.Name.ToString();

1 Answer 1

0

You should use

var list =cxt.Web.GetList("sites/Processing/Shared%20Documents")

To get the specific file:

File file = cxt.Web.GetFileByServerRelativeUrl("/sites/Processing/Shared%20Documents/test.doc");
cxt.Load(file);
cxt.ExecuteQuery(); 
Console.WriteLine(file.Name);
Console.ReadKey();
9
  • It returns the same error :(
    – leebongee
    Commented Sep 22, 2020 at 8:33
  • if i want to get file from specific file %2Fsites%2FProcessing%2FShared%20Documents%2FGeneral%2FApp2020 then what should I do in that code?
    – leebongee
    Commented Sep 22, 2020 at 8:36
  • Check my updated answer, Commented Sep 22, 2020 at 8:50
  • It has not worked. And still returns file not found :(
    – leebongee
    Commented Sep 22, 2020 at 8:59
  • when I set var targetSiteURL = new Uri("https://mycompany.sharepoint.com"); and var list =cxt.Web.GetList("/Shared%20Documents") then it worked, but when I set var list =cxt.Web.GetList("/sites/Processing/Shared%20Documents") then it return file not found since that
    – leebongee
    Commented Sep 22, 2020 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.