How to remove a WebPartZone programmatically? RRS feed

  • Question

  • Created a subsite and inserted a webpart in WebPartZone left. But the default.aspx page has the right WebPartZone , which is taking up space. I need eliminate the  WebPartZone right programmatically. Does anyone know how to do this?

                using (SPSite site = new SPSite(fullSiteUrl.Substring(0, siteIndex)))
                    using (SPWeb newWeb = site.OpenWeb())
                        newWeb.AllowUnsafeUpdates = true;
                        SPWebCollection subsites = newWeb.Webs;
                        SPWeb newSubWeb = subsites.Add(fullSiteUrl.Substring(siteIndex + 1), siteName, "", 1033, "STS#1", true, false);
                        SPLimitedWebPartManager webParts = newSubWeb.GetLimitedWebPartManager(fullSiteUrl + "/default.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
                        AnunciosWP wp = new AnunciosWP();
                        wp.Title = "Anúncios";
                        wp.WebSite = urlList;
                        wp.SubSiteId = subSiteId;                    
                        webParts.AddWebPart(wp, "Left", 0);

    Willian Fakri Bratkauskas

    Sunday, August 18, 2013 3:19 PM


  • Hi,

    There is no need to remove the right webpart zone. You can make the left webpart zone occupy the entire space easily by using CSS itself. There is a class called "col-50" which has a width of "49.9%" and it causes the left zone to shrink. You can just override that class attribute and make the width as "100% !important" in your custom CSS or content editor webpart style tags.

    Having said that, the better way to resolve your problem is to use a proper Page Layout and/or place your webpart in a proper place in the layout. There are many out of the box page layouts and you can also build custom Page Layouts too. 


    ******If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful*******

    Sunday, August 18, 2013 11:44 PM