Share via

GraphServiceClient - getting sharepoint folder data - gets stucked

Alessandra Bonomo 1 Reputation point
2021-07-13T07:25:09.523+00:00

I need to check if a a folder exists in sharepoint : if it doesn't exists I need to create it
This is my call:

Await graphClient.Sites(MySiteId).Drive.Items(MyFolderId).Request.GetAsync

If my MyFolderIdexists it all works fine, but if it doesn't exists the call remains stuck indefinitely

In general I notice that each time I make a graph call, using GraphClient, that looks for something that doesn't exists in sharepoint I get stucked
By now, not to block my application, I'm using a timeout, checking if the result status is RanToCompletion . But I can never know whether my call has an error, a simple timeout or a not found exception:
Dim itemsInFolderRequest = graphClient.Sites(SharePointSiteID).Drive.Items(SharePointParentFolderId).Children.Request
Dim itemsInFolder = itemsInFolderRequest.GetAsync
Await Task.WhenAny(itemsInFolder, Task.Delay(m_GraphRquestTimeoutMs))
If itemsInFolder IsNot Nothing AndAlso itemsInFolder.Status = Threading.Tasks.TaskStatus.RanToCompletion Then
'only here I'm sure I can read results
else
'here I don't know what happened
End If

Is there a way to make the
Await graphClient.Sites(MySiteId).Drive.Items(MyFolderId).Request.GetAsync
work without blocking, returning me a simple "Not found"?

Windows development | Windows API - Win32
Microsoft Security | Microsoft Graph
0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.