Monday, November 19, 2012

Closed Web Parts in SharePoint - How to Find, Restore and Delete

Closed Web Parts? What are they?

When users don't need a particular web part on the page, they click on Edit drop down from Web Part Menu, and choose "Close" instead of Delete. They prefer Close rather Delete which is obvious!

Technically, When you close a Web Part, It doesn't appears on the screen. But still running on the background and eating up the resources. Its a best practice to delete the closed web parts. Because, closed Web parts takes up the memory and could cause impact on performance.
sharepoint closed web part

How to Find closed web parts from SharePoint Interface

How to find closed Web Parts? Open the Web Part page in Web Part Maintenance Mode (Just append ?contents=1 at the end in address bar). E.g. http://SharePoint.com/sites/sales/default.aspx?contents=1  and look for "No" value under Open on Page? column.
find closed web parts sharepoint 2010
 

How to Delete Closed Web Parts using SharePoint Interface

From the Web Part Maintenance Mode, choose the web parts which are in closed mode (Open on Page?  column value "No") and click on "Delete" from the Toolbar.
sharepoint 2010 delete closed web part

How to Stop Users from Closing a Web Part?
Simple! Go to the web part properties, In Advanced tab Disable "AllowClose" check-box!

How to Restore Closed Web Parts using SharePoint Interface

Accidental close of web parts may happen while you edit web part pages. Here is how to Restore closed web parts.
  1. Go to Site Actions >> Edit Page
  2. Click on "Add a Web Part" link
  3. Scroll down and select "Closed Web Parts" (In MOSS 2007, Go to Advanced Web Part gallery and options)
  4. Once you click, it will show all the web part which are closed on this page.
  5. Choose the web parts and click on "Add" to bring closed web part to the page.  how to restore closed webpart in sharepoint 2010

How to Find and Delete Closed Web Parts With PowerShell:

Well, If its a single page, We can use web part maintenance page to delete closed web parts. But for the whole site, its cumbersome. Closed web parts list can be retrieved by reading SharePoint Content Databases directly! But as per Microsoft's Advice lets not do it. Lets use PowerShell instead. This script will create a CSV file for logging Pages and closed web parts before deleting it.

#Add SharePoint Snap-in
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Write Header to CSV File 
"Page URL,  Web Part Name" | out-file ClosedWebParts.csv

#Get all Webs
$webs = Get-SPWebApplication "http://sharepoint.company.com" | Get-SPSite -Limit All | Get-SPWeb -Limit All

#Iterate through webs
foreach ($web in $webs) 
{
#Get All Pages from site's Root into $AllPages Array
$AllPages = @($web.Files | Where-Object {$_.Name -match ".aspx"})

#Search All Folders for Pages
foreach ($folder in $web.Folders)
    {
       #Add the pages to $AllPages Array
       $AllPages += @($folder.Files | Where-Object {$_.Name -match ".aspx"})
    }
 
 #Iterate through all pages
 foreach($Page in $AllPages)
  {
     $webPartManager = $web.GetLimitedWebPartManager($Page.ServerRelativeUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
   
     # Array to Hold Closed Web Parts 
    $closedWebParts = @()
                foreach ($webPart in $webPartManager.WebParts | Where-Object {$_.IsClosed})
                {
                 $result = "$($web.site.Url)$($Page.ServerRelativeUrl), $($webpart.Title)"
                 Write-Host "Closed Web Part(s) Found at: "$result
                 $result | Out-File ClosedWebParts.csv -Append 
                 $closedWebParts += $webPart
                }
    
    #Delete Closed Web Parts
    foreach ($webPart in $closedWebParts)
                {
                   Write-Host "Deleting '$($webPart.Title)' on $($web.site.Url)/$($page.Url)"
                   $webPartManager.DeleteWebPart($webPart)
                }
   
 }
 }        

So the rule of Thumb is: If you don't need a web part in a page, Delete it! You can export the web part and use it later, if you want.



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Five Challenges in SharePoint Security
...And How to Solve Them. Free White Paper
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...