0

I have problem with sharepoint when I try to get all file in a specific url. I've tried 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();
leebongee
  • 103
  • 1
  • 10
  • The error suggests that your URL is wrong. Obviously we can't check your site in order to verify that. – ADyson Sep 22 '20 at 09:02

1 Answers1

1

@leebongee,

The list url you specified in below code maybe not correct:

var list = cxt.Web.GetList("/Shared%20Doc...)

For example, if my site is : https://abc.sharepoint.com. And i want to get 'Shared Documents', then the url is:

var list = context.Web.GetList("Shared%20Documents");

If i want to get another generic list(https://abc.sharepoint.com/Lists/my/AllItems.aspx), then the url is:

var list = context.Web.GetList("Lists/my");

If my site is: https://abc.sharepoint.com/sites/s01, then code will be:

var list = context.Web.GetList("/sites/s01/Shared%20Documents");

And

var list = context.Web.GetList("/sites/s01/Lists/xxxx");

BR

Baker_Kong
  • 1,739
  • 1
  • 4
  • 9
  • thank you very much, I found that error and fixed it. But how can I get file in subfolder inside `/sites/s01/Shared%20Documents`? I'd tried this url `/sites/s01/Shared%20Documents/General/App` but it still return file in url `/sites/s01/Shared%20Documents` – leebongee Sep 23 '20 at 03:40
  • 1
    use [GetFolderByServerRelativeUrl](https://learn.microsoft.com/en-us/previous-versions/office/sharepoint-server/ee539339(v=office.15)) to get folder then `Folder.Files` – Baker_Kong Sep 23 '20 at 04:39
  • 1
    Or if you can find the correspoding item of that folder then [item.folder](https://learn.microsoft.com/en-us/previous-versions/office/sharepoint-server/jj171077(v=office.15)) – Baker_Kong Sep 23 '20 at 04:44