I am currently working on retrieving the siteId and listId from shared folders. So far I manage to do it on a Sharepoint folder where I have access to the Sharepoint root but when I use the URL of a shared Sharepoint location I am having the following error message: "Invalid hostname for the tenancy"
For a bit of context, my usecase is the following one:
- A colleague of mine shares a folder with me from a Sharepoint (xxx.sharepoint.com).
- I have access to his folder.
- If I simply go to the root (xxx.sharepoint.com) I am having "access denied" which is fine (I believe).
- I want to retrieve the sideId, listId (and eventually driveId) from the shared folder using the URL of this folder.
So far, as I said previously, I am able to retrieve those informations for a sharepoint folder where I do have access to the root. Unfortunatly, in my usecase previously describe I have an error and it is impossible to me to retrieve it even by retrieving all sites which I have access to or by getting the list from the folder URL.
The piece of code that I am using so far:
public async Task<List> UrlToList(string accessToken, string url)
{
url = url.Replace("/Forms/AllItems.aspx", "");
Uri uri = new Uri(url);
var segments = string.Join("", uri.Segments[0..^1]).TrimEnd('/');
var request = graphClient.Sites[uri.Host].SiteWithPath(segments).Lists.Request(Options(accessToken));
var lists = await request.GetAsync();
var list = lists.First(l => string.Compare(url, l.WebUrl, true) == 0);
return list;
}
I only see two options so far... It could come from the configuration of xxx.sharepoint.com or a problem of permission.
Is there any possible way to retrieve those informations? If so, how? And is there also any code sample available somewhere?