Quick Tip: Provisioning Web Parts to a Page

When deploying a page to SharePoint through a Modules feature, there are several options adding web parts to this. These are as follows:

  1. Add the web parts to the page programmatically via a feature receiver. This approach can be done quickly and easily if you are familiar with coding, however if the feature receiver fails, the web part page may continue to be checked out.
  2. Embed references to the web parts directly in the mark-up of the aspx page. The main problem with this approach is that once the page is deployed, the page is still “ghosted”. This means that the normal drop down to “Edit Web Part” is not shown, blocking future modifications to the page.
  3. The third approach (the preferred one), is to embed the webpart markup in “AllUsersWebPart” nodes in the modules elements.xml file (as shown in the example below).

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="XYZCustomPages" RootWebOnly="True">
<File Path="XYZCustomPages\Home.aspx" Url="Home.aspx" IgnoreIfAlreadyExists="true">
<AllUsersWebPart WebPartZoneID="Left" WebPartOrder="1">
<?xml version="1.0" encoding="utf-8"?>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<type name="SolutionX.ProjectY.WebParts.MyWebPart, $SharePoint.Project.AssemblyFullName$" />
<property name="Title" type="string">My WebPart</property>
<property name="Description" type="string">My WebPart for XYZ</property>
<property name="ListName" type="string">ExampleList</property>
<property name="RowLimit" type="string">5</property>

Cheers to Pete Mellish and Amardeep Bhogal, who i kicked around the pro’s and con’s with.

Rob Nowik

Senior Consultant

Microsoft Consulting Services UK

Click here to read my bio


Comments (9)

  1. Andreas says:


    thank you for the info but how do I avoid the following issue: andreasglaser.net/…/MOSS-2007-WCMS-development-ProvisionedFilesxml-and-strange-behavior-with-multiple-WebParts.aspx

    If I use this technique (SharePoint 2007) the WebPart will be added several times if you deactivate and activate the feature.



  2. Rob Nowik says:

    Hi Andreas,

    I have not come across this issue myself. Have you experienced this on 2010, or just 2007? Does this only occur when you provision "page layouts" with pre-baked webparts, or does it happen also for plain web part pages that are not deployed to the page layouts directory?

    It may be worth trying this with the ID attribute set on the AllUsersWebPart nodes, failing this you could try setting the IgnoreIfAlreadyExists flag.



  3. ABawa says:

    Can you share an example of using <AllUsersWebPart> tag to bake in an out of the box list view web part. Say, I want to put a task list on the page at the time of provisioning. How do I do that?

    Your response is much appreciated?

  4. Rob Nowik says:

    Hi ABawa,

    Instead of using the AllUsersWebPart tag in the elements.xml file, use the View tag. I'll post a blogpost over the next few days on how to do this.



  5. Gaurav Pitroda says:

    <?xml version="1.0" encoding="utf-8"?> at Line 7 seems redundant

  6. Momo says:

    In using the <AllUsersWebPart> approach, does this approach require code behind? Am new to this…if there is an example of this you can point me to or share, I would greatly appreciate it.

    Thanks :)

  7. Nik Patel says:

    Andreas is right.. This approach would add same web part multiple times if you activating and reactivating features. Here is waldek's article but answer is coded version, not declarative version.. :)

  8. Ashwane Singh says:

    If you are working with SP 2013 there is attribute "ReplaceContent ="true"" for <File>, this declarative provisioning of web part willl work then and wouldn't add multi webparts.

  9. Frank says:


    I was about to use your solution here but i found the styling of your page width made the code window truncated meaning i have to scroll right to see the end of the code lines.

    This is not acceptable, please update the design of your site so that i don't have to scroll ASAP.

    I've now had to take several moments out of my very busy schedule to give you this constructive feedback (which i will not charge you for) . Please ensure maximum efficiency from web design templates when considering the type of content which will be hosted.

    Regards, Frank (The (Panzer) Tank) O'Donnell