SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to know how to update title of Sharepoint web using REST. I have used REST to view the title but not sure how to update the title.

I can view the title by exploring http://urlofsite/_api/web/title also.

MSDN has given the code in js but not in c#.


share|improve this question
up vote 1 down vote accepted

I have figured it out by myself, this is how it will work. This is code is updating title of list, title of web can also be updated by changing the uri and post data.

    Uri uri = new Uri("http://sp2013vm/_api/web/lists/GetByTitle('Tasks')");            
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
    request.ContentType = "application/json;odata=verbose";
    request.Headers["X-RequestDigest"] = getDigestValue();
    request.Headers["X-HTTP-Method"] = "MERGE";
    request.Headers["IF-MATCH"] = "*";
    request.Credentials = CredentialCache.DefaultCredentials;
    request.Accept = "application/json;odata=verbose";
    request.Method = "POST";

    string stringData = "{ '__metadata': { 'type': 'SP.List' }, 'Title': 'New title' }";
    request.ContentLength = stringData.Length;
    StreamWriter writer = new StreamWriter(request.GetRequestStream());

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    StreamReader reader = new StreamReader(response.GetResponseStream());
share|improve this answer

When I tried to use the Ahmed`s solution, I got the following error:

Exception calling "Flush" with "0" argument(s): "Bytes to be written to the stream exceed the Content-Length bytes size specified." At C:\Scripts\UpdateItem.ps1:69 char:18
+     $writer.Flush <<<< ();
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

I resolve this error by replacing this command

request.ContentLength = stringData.Length;

To this command

encoder = new UTF8Encoding(false)
request.ContentLength = encoder.GetByteCount(stringData)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.