Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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#.

Thanks

share|improve this question
add comment

1 Answer 1

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());
    writer.Write(stringData);
    writer.Flush();

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

Your Answer

 
discard

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.