Remove a control from a page using the REST api

Posted by Community Admin on 04-Aug-2018 14:08

Remove a control from a page using the REST api

All Replies

Posted by Community Admin on 27-Mar-2014 00:00

Hi,

I have a question similar to one that was never fully resolved www.sitefinity.com/.../how-to-get-page-content-from-web-service

Using the Sitefinity REST API I would like to remove a specific control from all pages. Is there a way I can do this? What service can I use to get the controls on a particular page?

Currently I can get all pages using the API but not all controls on the page.

    var requestUri = "www.mywebsite.com/.../PagesService.svc";
    var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(requestUri);
    request.ContentType = "application/json";
    request.Headers["wrap_access_token"] = myAccessToken;
    request.Method = "GET";

    var response = (System.Net.HttpWebResponse)request.GetResponse();

    MyNamespace.ItemCollection<MyNamespace.Page> pages;
    using (var reader = new System.IO.StreamReader(response.GetResponseStream(), Encoding.UTF8))
   
        using (var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(reader.ReadToEnd())))
       
            var pagesSerializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(MyNamespace.ItemCollection<MyNamespace.Page>));
            pages = (MyNamespace.ItemCollection<MyNamespace.Page>)pagesSerializer.ReadObject(stream);
       
   

    response.Close();

    foreach (var page in pages.Items)
   
        // this is where I would loop though all the controls within the page and delete those of a specific type
   

This thread is closed