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.

Jignesh
  • 125
  • 8

1 Answers1

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);
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
  • Thanks it worked, but also how can i set conflict state "@microsoft.graph.conflictBehavior": "rename", while using this type of solution – Jignesh Dec 03 '20 at 10:39