1

I am trying to do File Copy operation in c# .net core using Microsoft graph API. It is an asynchronous operation, and by doc, it says it returns a location in the response header to check the status of the operation, Now the issue is I need its response header so that I can check the status of file copy operation but every time I am getting 'null' as value, I have tried following code,

DriveItem response = await graphClient.Sites[siteId].Drive.Items[itemId]
                           .Copy(fileName, parentReference)
                           .Request()
                           .PostAsync();

The driveItem returns null but I think at least it should have returned the additional data-carrying response status and location.

When I use online graph api it just works fine returning response and location, but it doesn't with graph client service.

1 Answer 1

2

Apparently it is an issue with msgraph-sdk-dotnet, at least it could be reproduced in 3.8.0 version, the error occurs while deserializing HTTP response. Probably it would be more beneficial to report it as a bug in referenced repository.

Meanwhile you could consider to construct a request for Copy a DriveItem endpoint and process response (including extracting Location header) as demonstrated below:

var message = graphClient.Sites[siteId].Drive.Items[itemId]
                .Copy(fileName, parentReference)
                .Request()
                .GetHttpRequestMessage();

message.Method = HttpMethod.Post;
var body = new DriveItemCopyRequestBody {Name = fileName, ParentReference = parentReference};
message.Content = new StringContent(graphClient.HttpProvider.Serializer.SerializeObject(body));
message.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var response = graphClient.HttpProvider.SendAsync(message).Result;
           
Console.Write(response.Headers.Location);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it worked, but also how can i set conflict state "@microsoft.graph.conflictBehavior": "rename", while using this type of solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.