I've got a URL to a folder on Sharepoint, and all I need to do is get a list of the files in that folder.
When I use my browser to go to https://<name>.sharepoint.com/Organisation/Section/Planning/
, I automatically get redirected to https://<name>.sharepoint.com/Organisation/Section/Planning/Forms/AllItems.aspx
, and I get to see the files present in that folder.
Now I want to get that same list of files in my desktop application. Here's what I have so far:
using (var Context = new ClientContext(fullUri.GetLeftPart(UriPartial.Authority)) {
AuthenticationMode = ClientAuthenticationMode.Default,
Credentials = new SharePointOnlineCredentials(username, password)
})
{
var folder = Context.Web.GetFolderByServerRelativeUrl(fullUri.AbsolutePath);
Context.Load(folder);
Context.Load(folder.Files);
Context.ExecuteQuery();
Console.WriteLine(folder.Name);
Console.WriteLine(folder.Files.Count);
foreach (var file in folder.Files)
Console.WriteLine(file.Name);
}
where fullUri = new Uri("https://<name>.sharepoint.com/Organisation/Section/Planning/");
.
Now this appears to work fine; folder.Name
prints as "Planning", which is as expected; however, the folder.Files.count
is always zero, 0.
But the browser shows that there is, indeed, a file present in that folder.
What am I doing wrong?!?
Update:
I've tried the REST request mentioned in the comments:
https://<name>.sharepoint.com/_api/web/getfolderbyserverrelativeurl('/Organisation/Section/Planning')/Files
which returns the following XML (which doesn't seem to contain much either :-\):
<?xml version="1.0" encoding="utf-8"?>
<feed xml:base="https://[name].sharepoint.com/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">
<id>a13a6953-4a31-4e76-a9ba-437e85261a43</id>
<title />
<updated>2018-03-16T17:08:04Z</updated>
<author>
<name />
</author>
</feed>
https://<name>.sharepoint.com/_api/web/getfolderbyserverrelativeurl('/Organisation/Section/Planning')/Files