I am using the following code to hide all WebParts in a page.
string siteUrl = "http://site"; SPSite site = new SPSite(siteUrl); SPWeb web; web = site.RootWeb; web.AllowUnsafeUpdates = true; Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager mgr = null; mgr = web.GetLimitedWebPartManager("pages/test.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.User); mgr.Web.AllowUnsafeUpdates = true; foreach (System.Web.UI.WebControls.WebParts.WebPart wp in mgr.WebParts) { wp.Hidden = true; mgr.SaveChanges(wp); } web.Dispose(); site.Dispose(); Test Page has a Content Editor WebPart, Few List View WebParts and a Custom Webparts. Code runs without any errors but does not hide the Content Editor WebPart and Custom Webpart.
I am running this code in a Sharepoint 2010 installation. Any ideas?
Note:
- I am not able to hide them using Web Interface as well.
- I am able to change other properties like Title using code and it works perfectly fine for all thr Web Parts.
- This code works if the user is given Full Permission for the whole site (I am expecting it to work when the user is given contribute permission for the page alone)This code used to work in MOSS 2007 and the user was given contribute permission for this page alone.