User Profile
mariscos25
Copper Contributor
Joined 3 months ago
User Widgets
Recent Discussions
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.20Views0likes0CommentsProblem copying file in SharePoint with Ms Graph v5.x
Hello. I need to copy a file in SharePoint, with Ms Graph v5.61 to a new folder (in the same library). The problem is that it copies but the process does not wait for it to complete and returns null, then I check and the file exists. I pass the code that I am using. public async Task<string?> CopyAsync(string listDriveId, string sourceDriveId, string destinationDriveId, string newName) { try { GraphSDK.Drives.Item.Items.Item.Copy.CopyPostRequestBody destinationInfo = new GraphSDK.Drives.Item.Items.Item.Copy.CopyPostRequestBody() { ParentReference = new ItemReference() { DriveId = listDriveId, Id = destinationDriveId }, Name = newName }; DriveItem? copy = await _graphClient.Drives[listDriveId].Items[sourceDriveId].Copy.PostAsync(destinationInfo); // Problem: "copy" is always null, but it is copied. When I check if the copied file exists, this file exists. if (copy != null) { return copy.Id; } } catch { } return null; } Can you help me? Thank you very much.18Views0likes0CommentsRe: Do you know any example to upload file to a specific folder (identified by folderId)? with Graph v5.
Hello. I've already found the problem: the MsGraph driveId is not the SharePoint Id, this was unknown to me (I need to study the principles of Microsoft 365 and Graph to have a solid foundation). This are bad ids: Good ids look like (34 chars) 01FEXZ******************BDPP. Good morning, sorry for the inconvenience.14Views0likes0CommentsDo you know any example to upload file to a specific folder (identified by folderId)? with Graph v5.
Hello. I'm just starting out with SharePoint and Microsoft 365. I need to upload a file to a specific folder in a SharePoint library using Graph v5.61. I've managed to upload it to the root of the library: publicasyncTask<string>UploadFile2Root(stringlistId,stringfileName,byte[]fileBytes) { stringfileId=""; Drive?drive=await_graphClient.Sites[SITE_ID].Lists[listId].Drive.GetAsync(); GraphSDK.Drives.Item.Root.RootRequestBuildertargetFolder=_graphClient.Drives[drive?.Id].Root; using(MemoryStreamstream=newMemoryStream(fileBytes)) { awaittargetFolder .ItemWithPath(fileName) .Content .PutAsync(stream); DriveItem?uploadedItem=awaittargetFolder.ItemWithPath(fileName).GetAsync(); fileId=uploadedItem?.Id??""; } returnfileId; } The problem is when I try to use a specific folder (folderId has the correct value): var targetFolder=_graphClient.Drives[drive?.Id].Items[folderId]; I always get the error: "Microsoft.Graph.Models.ODataErrors.ODataError: 'The resource could not be found.'" Could you tell me how to solve the problem or an example that does this task? I have also tried: https://learn.microsoft.com/en-us/answers/questions/1517434/how-to-upload-a-file-to-a-sharepoint-driveitem-fol and other examples, but without success. I'm also trying to retrieve something similar to an ItemRequestBuilder. Thank you very much in advance.41Views0likes1Comment
Groups
Recent Blog Articles
No content to show