How to PATCH data using System.Net.Http












0















I have uploaded a file to SharePoint and found out what id it has. Now I need to update some of the other columns on that listitem. The problem is that System.Net.Http.HttpMethod.Patch doesn't exist.



public static async Task<string> UpdateFileData()
{
var (authResult, message) = await Authentication.AquireTokenAsync();

string updateurl = MainPage.rooturl + "lists/edd49389-7edb-41db-80bd-c8493234eafa/items/" + fileID + "/";
var httpClient = new HttpClient();
HttpResponseMessage response;
try
{
var root = new
{
fields = new Dictionary<string, string>
{
{ "IBX", App.IBX }, //column to update
{ "Year", App.Year}, //column to update
{ "Month", App.Month} //column to update
}
};

var s = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat };
var content = JsonConvert.SerializeObject(root, s);
var request = new HttpRequestMessage(HttpMethod.Put, updateurl);
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
request.Content = new StringContent(content, Encoding.UTF8, "application/json");
response = await httpClient.SendAsync(request);
var responseString = await response.Content.ReadAsStringAsync();
return responseString;
}
catch (Exception ex)
{
return ex.ToString();
}
}









share|improve this question





























    0















    I have uploaded a file to SharePoint and found out what id it has. Now I need to update some of the other columns on that listitem. The problem is that System.Net.Http.HttpMethod.Patch doesn't exist.



    public static async Task<string> UpdateFileData()
    {
    var (authResult, message) = await Authentication.AquireTokenAsync();

    string updateurl = MainPage.rooturl + "lists/edd49389-7edb-41db-80bd-c8493234eafa/items/" + fileID + "/";
    var httpClient = new HttpClient();
    HttpResponseMessage response;
    try
    {
    var root = new
    {
    fields = new Dictionary<string, string>
    {
    { "IBX", App.IBX }, //column to update
    { "Year", App.Year}, //column to update
    { "Month", App.Month} //column to update
    }
    };

    var s = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat };
    var content = JsonConvert.SerializeObject(root, s);
    var request = new HttpRequestMessage(HttpMethod.Put, updateurl);
    request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
    request.Content = new StringContent(content, Encoding.UTF8, "application/json");
    response = await httpClient.SendAsync(request);
    var responseString = await response.Content.ReadAsStringAsync();
    return responseString;
    }
    catch (Exception ex)
    {
    return ex.ToString();
    }
    }









    share|improve this question



























      0












      0








      0


      0






      I have uploaded a file to SharePoint and found out what id it has. Now I need to update some of the other columns on that listitem. The problem is that System.Net.Http.HttpMethod.Patch doesn't exist.



      public static async Task<string> UpdateFileData()
      {
      var (authResult, message) = await Authentication.AquireTokenAsync();

      string updateurl = MainPage.rooturl + "lists/edd49389-7edb-41db-80bd-c8493234eafa/items/" + fileID + "/";
      var httpClient = new HttpClient();
      HttpResponseMessage response;
      try
      {
      var root = new
      {
      fields = new Dictionary<string, string>
      {
      { "IBX", App.IBX }, //column to update
      { "Year", App.Year}, //column to update
      { "Month", App.Month} //column to update
      }
      };

      var s = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat };
      var content = JsonConvert.SerializeObject(root, s);
      var request = new HttpRequestMessage(HttpMethod.Put, updateurl);
      request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
      request.Content = new StringContent(content, Encoding.UTF8, "application/json");
      response = await httpClient.SendAsync(request);
      var responseString = await response.Content.ReadAsStringAsync();
      return responseString;
      }
      catch (Exception ex)
      {
      return ex.ToString();
      }
      }









      share|improve this question
















      I have uploaded a file to SharePoint and found out what id it has. Now I need to update some of the other columns on that listitem. The problem is that System.Net.Http.HttpMethod.Patch doesn't exist.



      public static async Task<string> UpdateFileData()
      {
      var (authResult, message) = await Authentication.AquireTokenAsync();

      string updateurl = MainPage.rooturl + "lists/edd49389-7edb-41db-80bd-c8493234eafa/items/" + fileID + "/";
      var httpClient = new HttpClient();
      HttpResponseMessage response;
      try
      {
      var root = new
      {
      fields = new Dictionary<string, string>
      {
      { "IBX", App.IBX }, //column to update
      { "Year", App.Year}, //column to update
      { "Month", App.Month} //column to update
      }
      };

      var s = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat };
      var content = JsonConvert.SerializeObject(root, s);
      var request = new HttpRequestMessage(HttpMethod.Put, updateurl);
      request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
      request.Content = new StringContent(content, Encoding.UTF8, "application/json");
      response = await httpClient.SendAsync(request);
      var responseString = await response.Content.ReadAsStringAsync();
      return responseString;
      }
      catch (Exception ex)
      {
      return ex.ToString();
      }
      }






      c# sharepoint microsoft-graph






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 31 '18 at 0:24









      Dale Burrell

      3,33532655




      3,33532655










      asked Dec 30 '18 at 23:03









      CETCET

      608




      608
























          3 Answers
          3






          active

          oldest

          votes


















          1














          Modify the code as below.



          public static async Task<string> UpdateFileData()
          {
          var (authResult, message) = await Authentication.AquireTokenAsync();

          string updateurl = MainPage.rooturl + "lists/edd49389-7edb-41db-80bd-c8493234eafa/items/" + fileID + "/";
          var httpClient = new HttpClient();
          HttpResponseMessage response;
          try
          {
          var root = new
          {
          fields = new Dictionary<string, string>
          {
          { "IBX", App.IBX }, //column to update
          { "Year", App.Year}, //column to update
          { "Month", App.Month} //column to update
          }
          };

          var s = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat };
          var content = JsonConvert.SerializeObject(root, s);
          var request = new HttpRequestMessage(new HttpMethod("PATCH"), updateurl);
          request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
          request.Content = new StringContent(content, System.Text.Encoding.UTF8, "application/json;odata=verbose");
          response = await httpClient.SendAsync(request);
          var responseString = await response.Content.ReadAsStringAsync();
          return responseString;
          }
          catch (Exception ex)
          {
          return ex.ToString();
          }
          }


          Or we can also use REST API to update list item by ID.



          Refer to: SharePoint 2013 REST Services using C# and the HttpClient






          share|improve this answer































            1














            Can't you just use the HttpMethod class constructor?



            new HttpMethod("PATCH");


            Source: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpmethod.-ctor?view=netframework-4.7.2#System_Net_Http_HttpMethod__ctor_System_String_






            share|improve this answer































              0














              It dependents whether .NET Core or .NET Framework is utilized, in case of `.NET Core HttpClient.PatchAsync Method could be utilized.



              In case of .NET Framework ListItem could be updated like this:



              using (var client = new HttpClient())
              {
              client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
              client.BaseAddress = new Uri("https://graph.microsoft.com");

              var listItemPayload = new Dictionary<string, object>
              {
              {"Color", "Fuchsia"},
              {"Quantity", 934}
              };

              var requestContent = new StringContent(JsonConvert.SerializeObject(listItemPayload));
              requestContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
              var response = await client.PatchAsync(new Uri($"https://graph.microsoft.com/v1.0/sites/{siteId}/lists/{listId}/items/{itemId}/fields"), requestContent);
              var data = response.Content.ReadAsStringAsync().Result.ToString();
              }


              where PatchAsync is the extension method for HttpClient class:



              public static class HttpClientExtensions
              {
              public static async Task<HttpResponseMessage> PatchAsync(this HttpClient client, Uri requestUri, HttpContent iContent)
              {
              var method = new HttpMethod("PATCH");
              var request = new HttpRequestMessage(method, requestUri)
              {
              Content = iContent
              };

              HttpResponseMessage response = new HttpResponseMessage();
              try
              {
              response = await client.SendAsync(request);
              }
              catch (TaskCanceledException e)
              {
              Debug.WriteLine("ERROR: " + e.ToString());
              }

              return response;
              }
              }



              All the credits for extension method go to the author of this answer







              share|improve this answer

























                Your Answer






                StackExchange.ifUsing("editor", function () {
                StackExchange.using("externalEditor", function () {
                StackExchange.using("snippets", function () {
                StackExchange.snippets.init();
                });
                });
                }, "code-snippets");

                StackExchange.ready(function() {
                var channelOptions = {
                tags: "".split(" "),
                id: "1"
                };
                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                StackExchange.using("externalEditor", function() {
                // Have to fire editor after snippets, if snippets enabled
                if (StackExchange.settings.snippets.snippetsEnabled) {
                StackExchange.using("snippets", function() {
                createEditor();
                });
                }
                else {
                createEditor();
                }
                });

                function createEditor() {
                StackExchange.prepareEditor({
                heartbeatType: 'answer',
                autoActivateHeartbeat: false,
                convertImagesToLinks: true,
                noModals: true,
                showLowRepImageUploadWarning: true,
                reputationToPostImages: 10,
                bindNavPrevention: true,
                postfix: "",
                imageUploader: {
                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                allowUrls: true
                },
                onDemand: true,
                discardSelector: ".discard-answer"
                ,immediatelyShowMarkdownHelp:true
                });


                }
                });














                draft saved

                draft discarded


















                StackExchange.ready(
                function () {
                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53982148%2fhow-to-patch-data-using-system-net-http%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                1














                Modify the code as below.



                public static async Task<string> UpdateFileData()
                {
                var (authResult, message) = await Authentication.AquireTokenAsync();

                string updateurl = MainPage.rooturl + "lists/edd49389-7edb-41db-80bd-c8493234eafa/items/" + fileID + "/";
                var httpClient = new HttpClient();
                HttpResponseMessage response;
                try
                {
                var root = new
                {
                fields = new Dictionary<string, string>
                {
                { "IBX", App.IBX }, //column to update
                { "Year", App.Year}, //column to update
                { "Month", App.Month} //column to update
                }
                };

                var s = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat };
                var content = JsonConvert.SerializeObject(root, s);
                var request = new HttpRequestMessage(new HttpMethod("PATCH"), updateurl);
                request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
                request.Content = new StringContent(content, System.Text.Encoding.UTF8, "application/json;odata=verbose");
                response = await httpClient.SendAsync(request);
                var responseString = await response.Content.ReadAsStringAsync();
                return responseString;
                }
                catch (Exception ex)
                {
                return ex.ToString();
                }
                }


                Or we can also use REST API to update list item by ID.



                Refer to: SharePoint 2013 REST Services using C# and the HttpClient






                share|improve this answer




























                  1














                  Modify the code as below.



                  public static async Task<string> UpdateFileData()
                  {
                  var (authResult, message) = await Authentication.AquireTokenAsync();

                  string updateurl = MainPage.rooturl + "lists/edd49389-7edb-41db-80bd-c8493234eafa/items/" + fileID + "/";
                  var httpClient = new HttpClient();
                  HttpResponseMessage response;
                  try
                  {
                  var root = new
                  {
                  fields = new Dictionary<string, string>
                  {
                  { "IBX", App.IBX }, //column to update
                  { "Year", App.Year}, //column to update
                  { "Month", App.Month} //column to update
                  }
                  };

                  var s = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat };
                  var content = JsonConvert.SerializeObject(root, s);
                  var request = new HttpRequestMessage(new HttpMethod("PATCH"), updateurl);
                  request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
                  request.Content = new StringContent(content, System.Text.Encoding.UTF8, "application/json;odata=verbose");
                  response = await httpClient.SendAsync(request);
                  var responseString = await response.Content.ReadAsStringAsync();
                  return responseString;
                  }
                  catch (Exception ex)
                  {
                  return ex.ToString();
                  }
                  }


                  Or we can also use REST API to update list item by ID.



                  Refer to: SharePoint 2013 REST Services using C# and the HttpClient






                  share|improve this answer


























                    1












                    1








                    1







                    Modify the code as below.



                    public static async Task<string> UpdateFileData()
                    {
                    var (authResult, message) = await Authentication.AquireTokenAsync();

                    string updateurl = MainPage.rooturl + "lists/edd49389-7edb-41db-80bd-c8493234eafa/items/" + fileID + "/";
                    var httpClient = new HttpClient();
                    HttpResponseMessage response;
                    try
                    {
                    var root = new
                    {
                    fields = new Dictionary<string, string>
                    {
                    { "IBX", App.IBX }, //column to update
                    { "Year", App.Year}, //column to update
                    { "Month", App.Month} //column to update
                    }
                    };

                    var s = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat };
                    var content = JsonConvert.SerializeObject(root, s);
                    var request = new HttpRequestMessage(new HttpMethod("PATCH"), updateurl);
                    request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
                    request.Content = new StringContent(content, System.Text.Encoding.UTF8, "application/json;odata=verbose");
                    response = await httpClient.SendAsync(request);
                    var responseString = await response.Content.ReadAsStringAsync();
                    return responseString;
                    }
                    catch (Exception ex)
                    {
                    return ex.ToString();
                    }
                    }


                    Or we can also use REST API to update list item by ID.



                    Refer to: SharePoint 2013 REST Services using C# and the HttpClient






                    share|improve this answer













                    Modify the code as below.



                    public static async Task<string> UpdateFileData()
                    {
                    var (authResult, message) = await Authentication.AquireTokenAsync();

                    string updateurl = MainPage.rooturl + "lists/edd49389-7edb-41db-80bd-c8493234eafa/items/" + fileID + "/";
                    var httpClient = new HttpClient();
                    HttpResponseMessage response;
                    try
                    {
                    var root = new
                    {
                    fields = new Dictionary<string, string>
                    {
                    { "IBX", App.IBX }, //column to update
                    { "Year", App.Year}, //column to update
                    { "Month", App.Month} //column to update
                    }
                    };

                    var s = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat };
                    var content = JsonConvert.SerializeObject(root, s);
                    var request = new HttpRequestMessage(new HttpMethod("PATCH"), updateurl);
                    request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", authResult.AccessToken);
                    request.Content = new StringContent(content, System.Text.Encoding.UTF8, "application/json;odata=verbose");
                    response = await httpClient.SendAsync(request);
                    var responseString = await response.Content.ReadAsStringAsync();
                    return responseString;
                    }
                    catch (Exception ex)
                    {
                    return ex.ToString();
                    }
                    }


                    Or we can also use REST API to update list item by ID.



                    Refer to: SharePoint 2013 REST Services using C# and the HttpClient







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 2 at 9:13









                    LZ_MSFTLZ_MSFT

                    1,472146




                    1,472146

























                        1














                        Can't you just use the HttpMethod class constructor?



                        new HttpMethod("PATCH");


                        Source: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpmethod.-ctor?view=netframework-4.7.2#System_Net_Http_HttpMethod__ctor_System_String_






                        share|improve this answer




























                          1














                          Can't you just use the HttpMethod class constructor?



                          new HttpMethod("PATCH");


                          Source: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpmethod.-ctor?view=netframework-4.7.2#System_Net_Http_HttpMethod__ctor_System_String_






                          share|improve this answer


























                            1












                            1








                            1







                            Can't you just use the HttpMethod class constructor?



                            new HttpMethod("PATCH");


                            Source: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpmethod.-ctor?view=netframework-4.7.2#System_Net_Http_HttpMethod__ctor_System_String_






                            share|improve this answer













                            Can't you just use the HttpMethod class constructor?



                            new HttpMethod("PATCH");


                            Source: https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpmethod.-ctor?view=netframework-4.7.2#System_Net_Http_HttpMethod__ctor_System_String_







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Dec 31 '18 at 0:14









                            SzabSzab

                            1,053517




                            1,053517























                                0














                                It dependents whether .NET Core or .NET Framework is utilized, in case of `.NET Core HttpClient.PatchAsync Method could be utilized.



                                In case of .NET Framework ListItem could be updated like this:



                                using (var client = new HttpClient())
                                {
                                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                                client.BaseAddress = new Uri("https://graph.microsoft.com");

                                var listItemPayload = new Dictionary<string, object>
                                {
                                {"Color", "Fuchsia"},
                                {"Quantity", 934}
                                };

                                var requestContent = new StringContent(JsonConvert.SerializeObject(listItemPayload));
                                requestContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
                                var response = await client.PatchAsync(new Uri($"https://graph.microsoft.com/v1.0/sites/{siteId}/lists/{listId}/items/{itemId}/fields"), requestContent);
                                var data = response.Content.ReadAsStringAsync().Result.ToString();
                                }


                                where PatchAsync is the extension method for HttpClient class:



                                public static class HttpClientExtensions
                                {
                                public static async Task<HttpResponseMessage> PatchAsync(this HttpClient client, Uri requestUri, HttpContent iContent)
                                {
                                var method = new HttpMethod("PATCH");
                                var request = new HttpRequestMessage(method, requestUri)
                                {
                                Content = iContent
                                };

                                HttpResponseMessage response = new HttpResponseMessage();
                                try
                                {
                                response = await client.SendAsync(request);
                                }
                                catch (TaskCanceledException e)
                                {
                                Debug.WriteLine("ERROR: " + e.ToString());
                                }

                                return response;
                                }
                                }



                                All the credits for extension method go to the author of this answer







                                share|improve this answer






























                                  0














                                  It dependents whether .NET Core or .NET Framework is utilized, in case of `.NET Core HttpClient.PatchAsync Method could be utilized.



                                  In case of .NET Framework ListItem could be updated like this:



                                  using (var client = new HttpClient())
                                  {
                                  client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                                  client.BaseAddress = new Uri("https://graph.microsoft.com");

                                  var listItemPayload = new Dictionary<string, object>
                                  {
                                  {"Color", "Fuchsia"},
                                  {"Quantity", 934}
                                  };

                                  var requestContent = new StringContent(JsonConvert.SerializeObject(listItemPayload));
                                  requestContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
                                  var response = await client.PatchAsync(new Uri($"https://graph.microsoft.com/v1.0/sites/{siteId}/lists/{listId}/items/{itemId}/fields"), requestContent);
                                  var data = response.Content.ReadAsStringAsync().Result.ToString();
                                  }


                                  where PatchAsync is the extension method for HttpClient class:



                                  public static class HttpClientExtensions
                                  {
                                  public static async Task<HttpResponseMessage> PatchAsync(this HttpClient client, Uri requestUri, HttpContent iContent)
                                  {
                                  var method = new HttpMethod("PATCH");
                                  var request = new HttpRequestMessage(method, requestUri)
                                  {
                                  Content = iContent
                                  };

                                  HttpResponseMessage response = new HttpResponseMessage();
                                  try
                                  {
                                  response = await client.SendAsync(request);
                                  }
                                  catch (TaskCanceledException e)
                                  {
                                  Debug.WriteLine("ERROR: " + e.ToString());
                                  }

                                  return response;
                                  }
                                  }



                                  All the credits for extension method go to the author of this answer







                                  share|improve this answer




























                                    0












                                    0








                                    0







                                    It dependents whether .NET Core or .NET Framework is utilized, in case of `.NET Core HttpClient.PatchAsync Method could be utilized.



                                    In case of .NET Framework ListItem could be updated like this:



                                    using (var client = new HttpClient())
                                    {
                                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                                    client.BaseAddress = new Uri("https://graph.microsoft.com");

                                    var listItemPayload = new Dictionary<string, object>
                                    {
                                    {"Color", "Fuchsia"},
                                    {"Quantity", 934}
                                    };

                                    var requestContent = new StringContent(JsonConvert.SerializeObject(listItemPayload));
                                    requestContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
                                    var response = await client.PatchAsync(new Uri($"https://graph.microsoft.com/v1.0/sites/{siteId}/lists/{listId}/items/{itemId}/fields"), requestContent);
                                    var data = response.Content.ReadAsStringAsync().Result.ToString();
                                    }


                                    where PatchAsync is the extension method for HttpClient class:



                                    public static class HttpClientExtensions
                                    {
                                    public static async Task<HttpResponseMessage> PatchAsync(this HttpClient client, Uri requestUri, HttpContent iContent)
                                    {
                                    var method = new HttpMethod("PATCH");
                                    var request = new HttpRequestMessage(method, requestUri)
                                    {
                                    Content = iContent
                                    };

                                    HttpResponseMessage response = new HttpResponseMessage();
                                    try
                                    {
                                    response = await client.SendAsync(request);
                                    }
                                    catch (TaskCanceledException e)
                                    {
                                    Debug.WriteLine("ERROR: " + e.ToString());
                                    }

                                    return response;
                                    }
                                    }



                                    All the credits for extension method go to the author of this answer







                                    share|improve this answer















                                    It dependents whether .NET Core or .NET Framework is utilized, in case of `.NET Core HttpClient.PatchAsync Method could be utilized.



                                    In case of .NET Framework ListItem could be updated like this:



                                    using (var client = new HttpClient())
                                    {
                                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
                                    client.BaseAddress = new Uri("https://graph.microsoft.com");

                                    var listItemPayload = new Dictionary<string, object>
                                    {
                                    {"Color", "Fuchsia"},
                                    {"Quantity", 934}
                                    };

                                    var requestContent = new StringContent(JsonConvert.SerializeObject(listItemPayload));
                                    requestContent.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");
                                    var response = await client.PatchAsync(new Uri($"https://graph.microsoft.com/v1.0/sites/{siteId}/lists/{listId}/items/{itemId}/fields"), requestContent);
                                    var data = response.Content.ReadAsStringAsync().Result.ToString();
                                    }


                                    where PatchAsync is the extension method for HttpClient class:



                                    public static class HttpClientExtensions
                                    {
                                    public static async Task<HttpResponseMessage> PatchAsync(this HttpClient client, Uri requestUri, HttpContent iContent)
                                    {
                                    var method = new HttpMethod("PATCH");
                                    var request = new HttpRequestMessage(method, requestUri)
                                    {
                                    Content = iContent
                                    };

                                    HttpResponseMessage response = new HttpResponseMessage();
                                    try
                                    {
                                    response = await client.SendAsync(request);
                                    }
                                    catch (TaskCanceledException e)
                                    {
                                    Debug.WriteLine("ERROR: " + e.ToString());
                                    }

                                    return response;
                                    }
                                    }



                                    All the credits for extension method go to the author of this answer








                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Jan 1 at 15:02

























                                    answered Jan 1 at 11:26









                                    Vadim GremyachevVadim Gremyachev

                                    36.8k772115




                                    36.8k772115






























                                        draft saved

                                        draft discarded




















































                                        Thanks for contributing an answer to Stack Overflow!


                                        • Please be sure to answer the question. Provide details and share your research!

                                        But avoid



                                        • Asking for help, clarification, or responding to other answers.

                                        • Making statements based on opinion; back them up with references or personal experience.


                                        To learn more, see our tips on writing great answers.




                                        draft saved


                                        draft discarded














                                        StackExchange.ready(
                                        function () {
                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53982148%2fhow-to-patch-data-using-system-net-http%23new-answer', 'question_page');
                                        }
                                        );

                                        Post as a guest















                                        Required, but never shown





















































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown

































                                        Required, but never shown














                                        Required, but never shown












                                        Required, but never shown







                                        Required, but never shown







                                        Popular posts from this blog

                                        android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                                        SQL update select statement

                                        'app-layout' is not a known element: how to share Component with different Modules