msgraph-sdk-dotnet icon indicating copy to clipboard operation
msgraph-sdk-dotnet copied to clipboard

Unable to get a Special Folder by name using the GraphServiceClient.

Open MaxxDelusional opened this issue 6 months ago • 4 comments

Problem:

According to the docs, the request for a special folder should be GET /me/drive/special/{name}, however, there is no way to construct this path using the Graph SDK.

What I tried:

This does not work, because DriveRequestBuilder does not contain a definition for Special.

var result = await graphClient.Me.Drive.Special["approot"].GetAsync();

This will not work, because the slash will become url encoded.

var result = await graphClient.Me.Drives["special/approot"].GetAsync();

The C# example in the docs say to do this.

var result = await graphClient.Drives["{drive-id}"].Special["{driveItem-id}"].GetAsync();

But there is no drive-id to specify. Attempting to use null or empty string as the drive id created an invalid request url.

BaseGraphServiceClient does not contain a DriveRequestBuilder so we can't do something like this.

var result = graphClient.Drive.Special["approot"].GetAsync();

Potential Workaround:

The only way I have found to get the drive is by specifying the entire url, but clearly this is not ideal.

var result = await graphClient.Me.Drive
    .WithUrl("https://graph.microsoft.com/v1.0/drive/special/approot")
    .GetAsync();

Side Question: Is there a way to get the baseUrl from an instance of GraphServiceClient? Or any way to build a url with a relative path?

Suggestion:

Add SpecialRequestBuilder to DriveRequestBuilder or add handling for null drive-id in DrivesRequestBuilder.

The docs should also be updated, as the current C# example doesn't work. (You shouldn't need a drive-id, but the docs say to specify one).

MaxxDelusional avatar Aug 16 '24 14:08 MaxxDelusional