Wednesday, April 7, 2010

SharePoint WebPart Manager tool

After the many WinForm tools that I’ve created using the TreeView & PropertyGrid combo (much like the SharePoint Manager 2007 tool), I finally decided to create a reusable core allowing various plug-ins for the tree hierarchy structure and for the commands available for the different nodes. And here’s the first tool based on this little framework of mine – the WebPart Manager tool (download):

WPManager1

WPManager2

As you see from the screenshots the tool displays a hierarchical view of all web applications, site collections and sites down to the folder structure of each site with all files and web parts in web part page files. The property grid is populated only for the web part level (this way the tool is much faster and the display options for the different levels are actually configurable in the accompanying configuration XML files of the tool). The tool supports the standard web part operations normally available through the standard SharePoint web UI – save, export, delete, close, open and move a web part and on the file node level another set of useful commands is exposed – starting with the file specific actions – check in/out, overwrite check-in, discard check-out, publish (these are really handy especially for publishing pages since you need to have the file checked out first before you can modify or add web parts to the page); to batch web part oriented commands like: export all web parts, import/add/delete web parts and some really nice goodies – export module feature and import web parts from module element file. The UI of the tool includes a common dialog interface with a dialog form using again the PropertyGrid control in conjunction with several custom UIEditor classes to capture the required parameters for the selected command (check the tool to get an impression of it).

And here is a short list of the available commands in the tool:

For the web part level:

  • Save web part – saves the selected web part after you have changed its properties in the PropertyGrid control.
  • Export web part – exports a .webpart or .dwp file with the web part data to the file system.
  • Delete web part – deletes the web part from the page.
  • Close web part – closes the web part.
  • Open web part – opens a previously closed web part (available only for closed web parts).
  • Move web part – allows you to change the web part zone and zone order of the web part.

For the file level:

  • Check out – checks out the selected file (available only for files in libraries and if the file is not already checked out)
  • Check in minor – checks in minor the selected file (available only for files in libraries and if the file is checked out)
  • Check in major – checks in major the selected file (available only for files in libraries and if the file is checked out)
  • Check in overwrite– checks in with overwrite the selected file (available only for files in libraries and if the file is checked out)
  • Discard check out – discards the check-out of the selected file (available only for files in libraries and if the file is checked out)
  • Publish – publishes the selected file (available only for files in libraries and if the file was previously checked in to a draft state)
  • Export all web parts – exports all web parts in the selected file to a specified folder (saving the web parts as .webpart and .dwp files)
  • Import web part(s) – imports web parts from .webpart and .dwp files from a selected folder in the file system (you can specify one or several files). You need to also specify the target web part zone ID on the page and optionally the zone index for the first web part to be imported (the consecutive parts will be assigned incrementing indices)
  • Add web part(s) – adds web parts from a list of available web parts for the current site – the list consists of all non-system SharePoint lists (resulting in adding a ListView web part) in the site and all web parts available in the web part gallery of the site. You need to also specify the target web part zone ID on the page and optionally the zone index for the first web part to be added.
  • Delete web part(s) – deletes web parts from the page – you can select to delete all web parts on the page or just select one or several of them to be deleted.
  • Export module feature – exports a module feature with the current file to a specified folder. It exports a feature.xml and an elements.xml file together with the file of the page. The elements file contains a Module element with a single File element containing the web part definitions of all web parts on the page. There is an option to export only the elements file instead of the full feature which is handy when you want to quickly copy all web parts of one page to another one using the “Import web parts from module file” command. For publishing pages the File element is exported with all relevant Property elements.
  • Import web parts from module file – imports web parts from an elements file (containing a Module element with one or many File elements) of an existing module feature or one created with the “Export module feature” command. The command shows a dialog which allows you to select the elements file to be imported and after the file is chosen a drop down list gets populated with the available File elements in the Module elements file so that you can choose which File definition to be imported. The command automatically resolves any resource tokens and ~Site/~SiteCollection tokens if present in the Module file.

For the folder level:

  • Export module feature – analogous to the command with the same name on the file level with the difference that you can choose whether to export all files in the current folder or just a group of selected files. The same command is available on the site level too – in this case it exports all/selected files from the root folder of the site.

3 comments: