Skip to main content
added 271 characters in body
Source Link
Shoban
  • 1.1k
  • 1
  • 11
  • 32

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:

  1. I am not able to hide them using Web Interface as well.
  2. I am able to change other properties like Title using code and it works perfectly fine for all thr Web Parts.
  3. 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.

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:

  1. I am not able to hide them using Web Interface as well.
  2. I am able to change other properties like Title using code and it works perfectly fine for all thr Web Parts.

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:

  1. I am not able to hide them using Web Interface as well.
  2. I am able to change other properties like Title using code and it works perfectly fine for all thr Web Parts.
  3. 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.
Source Link
Shoban
  • 1.1k
  • 1
  • 11
  • 32

Hiding WebParts programatically does not work

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:

  1. I am not able to hide them using Web Interface as well.
  2. I am able to change other properties like Title using code and it works perfectly fine for all thr Web Parts.