Quick Tip: Provisioning a List View to a Web Part Page

Following on from my recent post (Provisioning Web Parts to a Page), I had a question asking how to do this for List Views. Below is a code sample showing how to do this…

   1: <?xml version="1.0" encoding="utf-8"?>
   2: <Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
   3:   <Module Name="XYZCustomPages" RootWebOnly="True">    
   4:     <File Path="XYZCustomPages\Home.aspx" Url="Home.aspx" IgnoreIfAlreadyExists="true">      
   5:       <View List="Lists/Tasks" BaseViewID="0" WebPartZoneID="Left" WebPartOrder="100">
   6:         <![CDATA[
   7:           <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
   8:             <Assembly>Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
   9:             <TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName>
  10:             <Title>My Tasks</Title>
  11:           </WebPart>
  12:         ]]>
  13:       </View>
  14:     </File>  
  15:   </Module>
  16: </Elements>


Rob Nowik

Senior Consultant

Microsoft Consulting Services UK


Comments (4)
  1. AjyBenny says:

    Hi Rob,

    I used your code sample to add programmatically list view web parts to an ASPX page. It worked very well, thank you very much for this.

    Do you know if I could use the same principle to add Excel web parts and Visio web parts to an ASPX page?

    Thanks in advance.

    AjyBenny, MCPD from Paris

  2. Steven says:

    Hi Rob,

    Is there anyway to set the Selected View?

    I would like to display the list as a Calendar (Selected View = Calendar)

    Thank you

  3. Kamlesh says:

    Can you provide same code for SharePoint 2013

  4. Riyaz says:

    Thanks for sharing knowledge, I am facing one issue when I used module to place the web part that when I configured query in the view using query string parameter it is not working when placed. But when I simply click edit web part and click on OK then it starts working.

    What should I do?

Comments are closed.

Skip to main content