Share via

SharePoint: Graph api UpdateAsync returns itemNotFound but still updates the file's name

sahar fiuzati hagh 1 Reputation point
2022-05-18T11:49:23.853+00:00

Hi,

when I'm trying to move a file using Graph api UpdateAsync() method, if the Id of ParentReference is wrong, Graph api returns itemNotFound exception and doesn't move the file but still renames the file. This is my request:

             var destDriveItem = new DriveItem
            {
                ParentReference = new ItemReference
                {
                    Id = destDriveFolder.Id,
                    DriveId = destDrive.Drive.Id
                },
                Name = newFileName
            };

            await graphClient.Sites[srcSiteId].Drives[srcDrive.Drive.Id].Items[srcDriveItem.Id]
                                .Request()
                                .UpdateAsync(destDriveItem);

Is there any flag that I can use to make the Update call atomic somehow?

BR

Microsoft 365 and Office | SharePoint | Development
0 comments No comments

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,496 Reputation points Microsoft External Staff
    2022-05-19T02:17:43.88+00:00

    Hi @sahar fiuzati hagh ,
    Per my test, the code will run to update the item which id is srcDriveItem.Id in await graphClient.Sites[srcSiteId].Drives[srcDrive.Drive.Id].Items[srcDriveItem.Id] which
    equivalent to PATCH /sites/{site-id}/drive/items/{item-id}. If you print the srcDriveItem.Id out. It might different with the id in ParentReference.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    Was this answer helpful?


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.