Placing webparts in the webpart gallery when you create a site.

1 minute read

Normally when you develop webparts you have to place the webparts in the webpart gallery before you can add them to your page. When you develop webparts for a customer this isn’t something you want. So I googled around and found out that you can also add them to the webpart gallery in your onet.xml of the site you are going to create. To do this you have to add a module just like I explained in my blog post Inserting initial information in a site definition,so this is kind of a part two of that blog post. First of all you add a module to the configuration in the onet.xml that you are going to use like this:

<Module Name="WebPartPopulation" />

‘WebPartGalleryPopulation’ is the name I created for my module. You have to specify the module at the end of the onet.xml between the tag just before the end tag of projects. The module you could enter there could be something like this:

 <Module Name="WebPartPopulation" List="113" Url="_catalogs/wp" Path="lists\wplib\dwp" RootWebOnly="TRUE">
    <File Url="MSContentEditor.dwp" Type="GhostableInLibrary" />
 </Module>

[sourcecode lang="xml"] [/sourcecode] The attributes that you add are described below:

  • URL:The directory off the web part gallery.
  • Path: Specifies the path of the webpart files. This can be files with the dwp extension or the webpart extension. To get this files you can create a export of your webpart in the user environment of SharePoint.
  • RootWebOnly: If you set this option to true is specifies that the files will be created only for the top-level site of a site collection.

So know you can create a site definition with webpart already populated in the webpart gallery.

 

Happy SharePointing.