Forum Discussion
mariscos25
Dec 02, 2024Copper Contributor
Does MsGraph v5.61.0 and SharePoint have a bug?
Hello.
It allows searching for folders in the "root" of a library using "tolower(Name) eq" but it does not allow the same in subfolders. I attach the method where I detected the problem.
public async Task<string?> FolderExistsAsync(string listDriveId, string? folderParentDriveId, string subfolderName)
{
try
{
if (folderParentDriveId == null) // root
{
// Ok (best solution, search in server-SharePoint)
DriveItemCollectionResponse? folderSearch = await _graphClient.Drives[listDriveId]
.Items
.GetAsync(q => q.QueryParameters.Filter = $"tolower(Name) eq '{subfolderName.ToLower()}'");
return folderSearch?.Value?[0]?.Id;
}
else
{
// Ok (bad solution, search in client)
DriveItemCollectionResponse? childrens = await _graphClient.Drives[listDriveId].Items[folderParentDriveId].Children.GetAsync();
DriveItem? subfolder = childrens?.Value?
.FirstOrDefault(item => item.Name?.Equals(subfolderName, StringComparison.OrdinalIgnoreCase) == true && item.Folder != null);
return subfolder?.Id;
//// Err: in Ms Graph v5.61.0?.
////var debugAux = await _graphClient.Drives[listDriveId].Items[folderParentDriveId].Children.GetAsync(); // Ok
//DriveItemCollectionResponse? childrens = await _graphClient.Drives[listDriveId].Items[folderParentDriveId].Children
// .GetAsync(q => q.QueryParameters.Filter = $"tolower(Name) eq '{subfolderName.ToLower()}'");
// Err: Microsoft.Graph.Models.ODataErrors.ODataError: 'Item not found'
//return childrens?.Value?.FirstOrDefault()?.Id;
}
}
catch { }
return null;
}
Thanks.
No RepliesBe the first to reply