Thursday, April 8, 2010

Schema.xml, onet.xml and baseview doesn’t pick up scope attribute

Again some strange things with SharePoint 2010 (maybe also with MOSS 2007) when using custom list template and a list view web part. It turns out that not all settings from the schema.xml are used in the web part view.

So I created a list template based on document library, added a custom view like this:

<View BaseViewID="41" Type="HTML" WebPartZoneID="Main" DisplayName="LatestChanges" Scope="Recursive" DefaultView="FALSE" TabularView="FALSE" MobileView="FALSE" MobileDefaultView="FALSE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/dlicon.png" Url="Forms/LastChanges.aspx">
        <XslLink Default="TRUE">main.xsl</XslLink>
        <RowLimit Paged="TRUE">10</RowLimit>
        <Toolbar Type="Standard">
        </Toolbar>
        <ViewFields>
          <FieldRef Name="DocIcon" />
          <FieldRef Name="LinkFilename" />
          <FieldRef Name="Modified" />
          <FieldRef Name="Editor" />
        </ViewFields>
        <Query>
          <OrderBy>
            <FieldRef Name="Modified" Ascending="FALSE" />
          </OrderBy>
        </Query>
        <ParameterBindings>
          <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noitemsinview_doclibrary)" />
          <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noitemsinview_doclibrary_howto2)" />
        </ParameterBindings>
      </View>

The view should display the last 10 modified documents, without showing folders. So I changed the Rowlimit, the Orderby and set Scope attribute to Recursive.

To provision a site with a page, with (my custom) document list I added this line to the onet.xml:

<List FeatureId="f8525c7b-c680-4431-94aa-4bb6e55827b5" Type="10000" Title="$Resources:core,shareddocuments_Title;" Url="$Resources:core,shareddocuments_Folder;" QuickLaunchUrl="$Resources:core,shareddocuments_Folder;/Forms/AllItems.aspx"/>

Make sure the web part is set to the correct view added this line to the onet.xml:

<View List="$Resources:core,shareddocuments_Folder;" BaseViewID="41" WebPartZoneID="TopRow" WebPartOrder="2" />

After depoying, and testing the provisioned page with the web part view is created and it looks like all settings of the BaseViewID, in this case 41, are copied to the view settings of the web part. However it does not copy all settings, the Scope="Recursive" is not copied. It turns out that the Scope="Recursive" should be set on the <View> element in the onet.xml itself. So the onet.xml should have a line like this:

<View List="$Resources:core,shareddocuments_Folder;" BaseViewID="41" Scope="Recursive" WebPartZoneID="TopRow" WebPartOrder="2" />

Now the scope is set correctly and the folders are not shown in the web part.

BTW: I don’t know if this is a bug. However when you change the web part view by hand and select the view ‘LatestChanges’, than it does copy the Scope attribute.

3 comments:

  1. Thanks for this. I thought I was going mad. It certainly sounds like a bug to me.

    ReplyDelete
  2. Scope="Recursive" worked for me in sharepoint2013. I modified the Schema.xml of document library to add that attribute

    ReplyDelete

Note: Only a member of this blog may post a comment.