Friday, April 22, 2011

Module feature: ListViewWebPart how to hide the toolbar?

 I have a module feature for the default page with ListViewWebPart on it:

<View Type="CALENDAR" List="$Resources:core,lists_Folder;/DiscussionReview" BaseViewID="2" WebPartZoneID="BottomLeft" WebPartOrder="1" Scope="Recursive">
        <![CDATA[
            <WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
            <Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
            <TypeName>Microsoft.SharePoint.WebPartPages.ListViewWebPart</TypeName>
            <Title>At-Risk Discussions</Title>
          <AllowMinimize>false</AllowMinimize>
          <AllowHide>false</AllowHide>
          <AllowRemove>false</AllowRemove>                    
            </WebPart>
            ]]>
      </View>
I want to hide the toolbar on that webpart.

I can do it through UI (Edit Page-> (If the webpart in the zone - I can access to the web part properties)-> chose a webpart and click edit -> Modify Shared web part->Toolbar Type->No Toolbar):

But I want to make this change in my SharePoint project and make it deploybale.
The Toolbar Type is not a property of the webpart, but the view itself.
SPView.ToolbarType Property (MSDN)

In this case, I can change this Toolbar Type property in the view in schema.xml:


<Toolbar Type="None">

P.S. To my delight - this change got propagated to already created list without any complications.