Question

I want to update a field 'End Time' of type DateTime in my Sharepoint list. I want to update the field('End Time') with null.Whenever I try this I get an exception "Input string is not in correct format". beloq is my code:

  public static void DeleteEndTime(string resource, string digest, Cookie cookie)
    {
        try
        {
            var client = new RestClient();
            client.BaseUrl = new Uri(_baseUri);
            var request = new RestRequest();
            request.AddParameter(cookie.Name, cookie.Value, ParameterType.Cookie);
            request.AddHeader("Accept", "application/json");
            request.AddHeader("Content-Type", "application/json;odata=verbose");
            request.AddHeader("X-RequestDigest", digest);
            request.AddHeader("X-HTTP-Method", "MERGE");
            request.AddHeader("IF-MATCH", "*");
            request.Resource = resource;
            request.RequestFormat = DataFormat.Json;
            request.Method = Method.POST;
            string jsonbody = @"{ '__metadata':{ 'type':'SP.Data.TimesheetListItem'},'End_x0020_Time':'"+ (DateTime?)null +"'}";
            request.AddParameter("Application/Json;odata=verbose", jsonbody, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

        }
        catch (Exception ex)
        {
            //TODO - Log
        }
    }
Était-ce utile?

La solution

Your request body should be like following.

string jsonbody = @"{ '__metadata':{ 'type':'SP.Data.TimesheetListItem'},'End_x0020_Time':null}"

So try it.

'End_x0020_Time':'"+ (DateTime?)null +"' is not valid. For null values, casting is not required.

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top