question

15489348 avatar image
0 Votes"
15489348 asked ·

I am trying to update a list item in sharepoint. I am using the code below it returns Bad Request. any idea Thanks in advance...

 string cont = "{ '__metadata': { 'type': 'SP.IssuesListItem' }, 'Status': 'Close'}";
 var content = new StringContent(cont, Encoding.UTF8, "application/json");
 string url = "https://mywebsite.com/_api/web/lists/GetByTitle('tasks')/items?$filter=ID eq 932"
    
 var credential = new System.Net.NetworkCredential(
                 "username",
                 "password",
                 "domain");
    
             using (var handler = new HttpClientHandler() { Credentials = credential, UseProxy = false })
             {
                 using (var client = new HttpClient(handler))
                 {
    
    
                     client.DefaultRequestHeaders.Accept.Clear();
                        
                     client.DefaultRequestHeaders.Add("X-HTTP-Method", "MERGE");
                     var mediaType = new MediaTypeWithQualityHeaderValue("application/json");
                     mediaType.Parameters.Add(new NameValueHeaderValue("odata", "nometadata"));
                     client.DefaultRequestHeaders.Accept.Add(mediaType);
                     client.DefaultRequestHeaders.Add("X-RequestDigest", await GetRequestDigest());
                     client.DefaultRequestHeaders.Add("binaryStringRequestBody", "true");
                     client.DefaultRequestHeaders.Add("IF-MATCH", "*");
    
                     HttpResponseMessage response = await client.PostAsync(url, content);
                     response.EnsureSuccessStatusCode();
                     return true;
                 }
             }
dotnet-csharpsharepoint-devdotnet-aspnet-core-general
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

PeterFleischer-3316 avatar image
0 Votes"
PeterFleischer-3316 answered ·

Hi,
did you convert your password to SecureString?

  string pwString = "password";
  System.Security.SecureString pwSecure = new System.Security.SecureString();
  foreach (var c in pwString) pwSecure.AppendChar(c);

  var credential = new System.Net.NetworkCredential(
                  "username",
                  pwSecure,
                  "domain");
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.