Powershell – Web Part Finder

November 25, 2010 7 comments

I finally found time to write a powershell script that would go out and look at every page for a specific web part. It was actually quite a bit easier than I thought once I got past the learning curve of powershell. I found it to be a little intimidating at first but quickly realized how powerful it truly can be. Looks like I will be doing a ton of scripting from now on.

Anyway, I figured someone would need something like this at some point so here it is. Enjoy!

Works with both 2007 and 2010

#===================================================================================
function Find-WebParts([String]$webUrl=$(throw ‘Parameter -Url is missing’))
{
write-host “Starting Analysis…”
write-host “”
$site = New-Object -TypeName “Microsoft.SharePoint.SPSite” -ArgumentList $webUrl
$web = $site.OpenWeb()
#Start with the root site
Get-WebPartDetails($webUrl)
#Start looking at all subsites and the subsites of those sites
Get-Subsites($webUrl)
write-host “”
write-host “Done.”
}

#===================================================================================
# Get the subsites and the subsites of those sites
#===================================================================================
function Get-Subsites($Url)
{
$WebCollection = Get-WebCollection($Url)
foreach($site in $WebCollection)
{
if($site.url -like “http*”)
{
Get-WebPartDetails($site.url)
}
if($site.url -like “http*”)
{
Get-Subsites($site.url)
}
}
}

#===================================================================================
# Return all webs within a site
#===================================================================================
function Get-WebCollection($Url)
{
$site = New-Object -TypeName “Microsoft.SharePoint.SPSite” -ArgumentList $Url
$web = $site.OpenWeb()
$WebCollection = $web.webs
return $WebCollection
}

#===================================================================================
# This function goes through all the lists for the given url and looks for
# documentlibraries that contain files with an .aspx extension
#===================================================================================
function Get-WebPartDetails ([String]$webUrl)
{
$site = New-Object -TypeName “Microsoft.SharePoint.SPSite” -ArgumentList $webUrl
$web = $site.OpenWeb()
$lists = $web.Lists
ForEach($list in $lists)
{
#Check if document library
if($list.BaseType -eq “DocumentLibrary”)
{
$items = $list.Items

foreach($item in $items)
{
if($item.Name -like “*.aspx”)
{
$pageurl = $web.Url + “/” + $item.Url
[Microsoft.SharePoint.SPFile]$file = $item.File
$mgr = $file.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
foreach($wp in $mgr.WebParts)
{
$match = “*” + $WebPartName + “*”
if($wp.GetType().BaseType -like $match)
{
write-host $wp.GetType().BaseType”,” $wp.GetType().Name”,” $pageurl
}
}
}
}
}

}

}

Love these errors!

November 8, 2010 Leave a comment

Is it really that bad?

Categories: Uncategorized

Adding Administration Links in SharePoint

I just recently started digging around trying to figure out how to add links to Central Administration or to the site collection settings page. The entire process is actually extremely simple. Here is a breakdown of the process:

  1. Create a solution in Visual Studio
  2. Add a feature
  3. Add an Empty Element to the project
  4. In the Elements.xml file add the following XML:

<?xml version=”1.0″ encoding=”utf-8″?>

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;

<CustomAction

Id=”F1E874CF-D433-445C-A62A-C0D8BF8D2AAA”

Location=”Microsoft.SharePoint.Administration.Applications”

Title=[PUT LINK TITLE HERE]

GroupId=”ServiceApplications”

Sequence=”15″

RequiredAdmin=”Delegated”

Description=[PUT DESCRIPTION HERE] >

<UrlAction Url=”[PATH TO YOUR FILE ”  />

</CustomAction>

</Elements>

Then is it a simple matter of deploying your solution. The above highlighted items can be changed to set the location of where the link appears. Below is are tables that you can use a reference.

The location and group ID values identify a specific place where the custom action must be created (or hidden). See below the possible combinations for both attributes.

2007

Description Location Group ID
Display form toolbar DisplayFormToolbar N/A
Edit form toolbar EditFormToolbar N/A
New form toolbar NewFormToolbar N/A
List view toolbar ViewToolbar N/A
List item context menu EditControlBlock N/A
New menu for list and document library view toolbars Microsoft.SharePoint.StandardMenu NewMenu
Actions menu for list and document library view toolbars Microsoft.SharePoint.StandardMenu ActionsMenu
Settings menu for list and document library view toolbars Microsoft.SharePoint.StandardMenu SettingsMenu
Upload documents menu for document libraries Microsoft.SharePoint.StandardMenu UploadMenu
Site Actions menu Microsoft.SharePoint.StandardMenu SiteActions
Site Settings Site Collection Administration links Microsoft.SharePoint.SiteSettings SiteCollectionAdmin
Site Settings Site Administration links Microsoft.SharePoint.SiteSettings SiteAdministration
Site Settings Galleries Links Microsoft.SharePoint.SiteSettings Galleries
Site Settings Look and Feel links Microsoft.SharePoint.SiteSettings Customization
Site Settings Users and Permissions links Microsoft.SharePoint.SiteSettings UsersAndPermissions
Site Actions menu for surveys Microsoft.SharePoint.StandardMenu ActionsMenuForSurvey
Site Settings links for surveys Microsoft.SharePoint.SiteSettings SettingsMenuForSurvey
Content Type Settings links Microsoft.SharePoint.ContentTypeSettings N/A
Central Administration Operations page Microsoft.SharePoint.Administration.Operations N/A
Central Administration Application Management page Microsoft.SharePoint.Administration.ApplicationManagement N/A

2010

Location Custom Action Group ID Group Description Default Custom Action IDs
CommandUI.Ribbon.ListView Not applicable Location corresponds to the list view.
CommandUI.Ribbon.NewForm Not applicable Location corresponds to the new form for the list.
CommandUI.Ribbon.EditForm Not applicable Location corresponds to the edit form for the list.
CommandUI.Ribbon.DisplayForm Not applicable Location corresponds to the display form for the list.
CommandUI.Ribbon Not applicable Location corresponds to the list view and edit, new, and display forms for the list.
DisplayFormToolbar Not applicable Location corresponds to the display form toolbar of lists. ExportEventToolbarButton (calendars) 

ExportContactToolbarButton (contacts)

EditControlBlock Not applicable Location corresponds to the per-item edit control block (ECB) menu.
EditFormToolbar Not applicable Location corresponds to the edit form toolbar of lists.
Microsoft.SharePoint.Administration.ApplicationCreated Links Application Created page. CreateSite 

HomePage

Microsoft.SharePoint.Administration.ApplicationManagement ApplicationSecurity Application Security section on Central Administration Application Management page.
  • WebPartSecurity
  • SelfService
  • WebApplicationSecurity
  • ManagePolicy
  • ManageAuthenticationProviders
Microsoft.SharePoint.Administration.

ApplicationManagement

ExternalService External Service Connections section on Central Administration Application Management page.
  • OfficialFile
  • HtmlViewer
  • DocConversion
Microsoft.SharePoint.Administration.ApplicationManagement SiteManagement SharePoint Site Management section on Central Administration Application Management page.
  • CreateSite
  • DeleteSite
  • SiteUse
  • QuotaDefinition
  • SiteQuota
  • SiteOwners
  • ListSiteCollections
Microsoft.SharePoint.Administration.ApplicationManagement WebApplicationConfiguration SharePoint Web Application Management section on Central Administration Application Management page.
  • Extend
  • Unextend
  • Delete
  • ManagedPaths
  • EmailSettings
  • GeneralSettings
  • ManageContentDatabases
  • ManageWebAppFeatures
  • ListWebApplications
Microsoft.SharePoint.Administration.ApplicationManagement WorkflowManagement Workflow Management section on Central Administration Application Management page. WorkflowManagement
Microsoft.SharePoint.Administration.Operations BackupRestore Backup and Restore section on Central Administration Operations page.
  • Backup
  • BackupHistory
  • Restore
  • BackupStatus
Microsoft.SharePoint.Administration.Operations DataConfiguration Data Configuration section on Central Administration Operations page.
  • DefaultDatabase
  • DataRetrieval
Microsoft.SharePoint.Administration.Operations GlobalConfiguration Global Configuration section on Central Administration Operations page.
  • RunningJobs
  • JobDefinitions
  • AlternateAccessMappings
  • ManageFarmFeatures
  • Solutions
Microsoft.SharePoint.Administration.Operations LoggingAndReporting Logging and Reporting section on Central Administration Operations page.
  • DiagnosticLogging
  • UsageAnalysis
Microsoft.SharePoint.Administration.Operations Security Security Configuration section on Central Administration Operations page.
  • ServiceAccount
  • Irm
  • Antivirus
  • BlockedFileTypes
  • AdministrationRoles
Microsoft.SharePoint.Administration.Operations Topology Topology and Services section on Central Administration Operations page.
  • FarmServers
  • TopologyServices
  • IncomingEmailServer
  • ApproveDGs
  • EmailConfiguration
Microsoft.SharePoint.Administration.Operations Upgrade Central Administration Operations page.
  • SiteUpgradeStatus
  • FinalizeUpgrade
Microsoft.SharePoint.ContentTypeSettings Fields Columns section on Site Collection Content Type page.
  • AddField
  • ReorderFields
Microsoft.SharePoint.ContentTypeSettings General Settings section on Site Collection Content Type page.
  • ChangeNameDescription
  • ChangeOptionalSettings
  • ChangeWorkflowSettings
  • RemoveContentType
Microsoft.SharePoint.ContentTypeTemplateSettings Fields Columns section on List Content Type page.
  • AddField
  • ReorderFields
Microsoft.SharePoint.ContentTypeTemplateSettings General Settings section on List Content Type page.
  • ChangeNameDescriptionGroup
  • ChangeOptionalSettings
  • ChangeWorkflowSettings
  • RemoveContentType
Microsoft.SharePoint.Create WebPages Web Pages section on Create page.
Microsoft.SharePoint.GroupsPage NewMenu New menu on site collection People and Groups page.
Microsoft.SharePoint.GroupsPage SettingsMenu Settings menu on site collection People and Groups page.
Microsoft.SharePoint.ListEdit Communications Communications section on Customize page for list or document library.
Microsoft.SharePoint.ListEdit GeneralSettings General Settings section on Customize page for list.
Microsoft.SharePoint.ListEdit Permissions Permissions and Management section on Customize page for list or document library.
Microsoft.SharePoint.ListEdit.DocumentLibrary GeneralSettings General Settings section on Customize page for document library.
Microsoft.SharePoint.PeoplePage ActionsMenu Actions menu on site collection People and Groups page.
Microsoft.SharePoint.PeoplePage NewMenu New menu on site collection People and Groups page.
Microsoft.SharePoint.PeoplePage SettingsMenu Settings menu on site collection People and Groups page.
Microsoft.SharePoint.SiteSettings Customization Look and Feel section on Site Settings page.
  • ProjectSettings
  • NavOptions
  • Theme
  • TopNav
  • QuickLaunch
  • SaveAsTemplate
  • ReGhost
Microsoft.SharePoint.SiteSettings Galleries Galleries section on Site Settings page.
  • MasterPageCatalog
  • ManageCType
  • ManageField
  • SiteTemplates
  • ListTemplates
  • WebParts
  • Workflows
Microsoft.SharePoint.SiteSettings SiteAdministration Site Administration section on Site Settings page.
  • RegionalSettings
  • LibrariesAndLists
  • WebUsage
  • UserAlerts
  • RSS
  • SrchVis
  • ManageSubWebs
  • ManageSiteFeatures
  • DeleteWeb
Microsoft.SharePoint.SiteSettings SiteCollectionAdmin Site Collection Administration section on Site Settings page.
  • DeletedItems
  • SiteCollectionUsage
  • Storage
  • ManageSiteCollectionFeatures
  • Hierarchy
  • Portal
Microsoft.SharePoint.SiteSettings UsersAndPermissions Users and Permissions section on Site Settings page.
  • PeopleAndGroups
  • SiteCollectionAdministrators
  • User
Microsoft.SharePoint.StandardMenu ActionsMenu Actions menu in list and document library views.
Microsoft.SharePoint.StandardMenu ActionsMenuForSurvey Site Actions menu for surveys.
Microsoft.SharePoint.StandardMenu NewMenu New menu in list and document library views.
Microsoft.SharePoint.StandardMenu SettingsMenu Settings menu in list and document library views.
Microsoft.SharePoint.StandardMenu SettingsMenuForSurvey Site Settings links for surveys.
Microsoft.SharePoint.StandardMenu SiteActions Site Actions menu.
Microsoft.SharePoint.StandardMenu UploadMenu Upload menu in document library views.
Microsoft.SharePoint.StandardMenu ViewSelectorMenu View selection menu for changing views provided on the list editing tab of the ribbon.
Microsoft.SharePoint.User ActionsMenu Actions menu on website Permissions page.
Microsoft.SharePoint.User NewMenu New menu on website Permissions page.
Microsoft.SharePoint.User SettingsMenu Settings menu on website Permissions page.
Microsoft.SharePoint.Workflows LeftNavBarLinks Left navigational area on pages for managing workflow.
NewFormToolbar Not applicable Location corresponds to the new form toolbar of lists.
ViewToolbar Not applicable Location corresponds to the toolbar in list views.
Categories: Uncategorized

Help With Picture Content Type

September 5, 2010 Leave a comment

I was playing with the picture content type today in SharePoint 2010 and I have run into a little issue and I’m not quite sure what the problem is. I’m hoping someone out there has had a similar experience or might know what I’m doing wrong.

Here are the steps I took:

  • Added Picture content type to a Shared Documents library on a team site
  • Modified the view to include the thumbnail column
  • Uploaded a GIF and a JPG to the library

The thumbnail column is unable to find the picture as you can see below.

I did notice that the thumbnail is looking for MMS_gif.jpg and the actual filename is MMS.gif so SharePoint must be doing something to it.

One more thing I noticed is that it works fine if the library is a picture library from the start.

Time to research…

UPDATE:

I have come across this blog entry that details the differences between the picture and image content types. Maybe the answer lies in there. Will keep posting as I find out more.

Document Sets in SharePoint 2010

September 2, 2010 Leave a comment

SharePoint 2010 has a new feature that introduces the concept of Document Sets. Essentially it is a grouping of files that are represented by a content type.  This new feature is to increase the viability of SharePoint as a functional DMS. Although the feature is good news and I can see it being widely used I don’t see it making SharePoint anymore attractive as a DMS. My main argument for this is that you have to upload any document directly to the document set. I would prefer to see the ability to group documents from various document libraries, essentially making the document location irrelevant.

I must admit that I have not used this feature extensively so if in fact I am missing something please point it out. Or perhaps suggest a way of extending the feature.

UPDATE:

Spoke too soon. Through the use of workflows or “Send to connections”  you can route documents to a repository (content organizer web service) and leave a link in the previous location. It just takes some creative thinking!

Categories: SharePoint 2010

The GridView ‘GridViewID’ fired event PageIndexChanging which wasn’t handled.

The forum entry found @ http://forums.asp.net/p/956540/1177923.aspx helped me out today. Below is the entry.

If you set AllowPaging=”true” or AllowSorting=”true” on a GridView control without using a DataSourceControl DataSource (i.e. SqlDataSource, ObjectDataSource), you will run into the following errors:

When changing the page on the GridView control:

The GridView ‘GridViewID’ fired event PageIndexChanging which wasn’t handled.

When clicking a column name to sort the column on the GridView control:

The GridView ‘GridViewID’ fired event Sorting which wasn’t handled.

As a result of not setting the DataSourceID property of the GridView to a DataSourceControl DataSource, you have to add event handlers for sorting and paging.

<asp:GridView ID=”gridView” OnPageIndexChanging=”gridView_PageIndexChanging” OnSorting=”gridView_Sorting” runat=”server” />

private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
   string newSortDirection = String.Empty;

   switch (sortDirection)
   {
      case SortDirection.Ascending:
        
newSortDirection = “ASC”;
         break;

      case SortDirection.Descending:
        
newSortDirection = “DESC”;
         break;
   }

   return newSortDirection;
}

protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
   gridView.PageIndex = e.NewPageIndex;
   gridView.DataBind();
}

protected void gridView_Sorting(object sender, GridViewSortEventArgs e)
{
   DataTable dataTable = gridView.DataSource as DataTable;

   if (dataTable != null)
   {
      DataView dataView = new DataView(dataTable);
      dataView.Sort = e.SortExpression + ” “ + ConvertSortDirectionToSql(e.SortDirection);

      gridView.DataSource = dataView;
      gridView.DataBind();
   }
}

Categories: Programming