Freigeben über


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="https://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="https://schemas.microsoft.com/WebPart/v2">
    8:             <Assembly>Microsoft.SharePoint, Version=14.0.0.0, 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_MugShot

Rob Nowik

Senior Consultant

Microsoft Consulting Services UK

ronowik@microsoft.com

Comments

  • Anonymous
    December 07, 2011
    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

  • Anonymous
    December 11, 2011
    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

  • Anonymous
    March 25, 2014
    Can you provide same code for SharePoint 2013

  • Anonymous
    April 23, 2014
    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?