April 16, 2007

MOSS: Setting list view title in ONET.XML

Problem:
Title of a list view (ListViewWebPart) cannot be defined in ONET.XML so it cannot be set different from the title of the list it is showing.

If I modify the title with a browser (Modify Shared Web Part / Appearance / Title) and save the site as a template the new title is nowhere in the .stp file, still if I use that template to create a site the changes are there.

Solution:
Use the WebPart tag and define the Title under it. In the following example a minimized List View Web Part is added with a title My custom title.

<View List="Documents" BaseViewID="11"
WebPartZoneID="Left" WebPartOrder="3" 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>My custom title</Title>
<FrameState>Minimized</FrameState>
</WebPart>
]]>
</View>

11 comments:

  1. Hi,

    I want to show the ListView webpart as minimized.

    In order to do this I need to change the Chrome State.

    Do i change it the same way you did with the Title?

    And what is the property I need to change??

    ReplyDelete
  2. You can have it minimized by defining

    <FrameState>Minimized</FrameState>

    ReplyDelete
  3. thanx for the really really fast reply. I have the code below in my onet.xml file.

    when I create the site from the site definition. the list is still displayed in the normal state.

    Is there anything i'm missing, some prerequisites maybe.

    like everything in sharepoint it looks really really simple. yet somehow it actually isn't.

    Code had been modified [ = < and
    ] = >


    [View List="Lists/RegelingenLinks" BaseViewID="0" WebPartZoneID="wpzLeft" WebPartOrder="4" ]
    [![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]
    [FrameState]Minimized[/FrameState]
    [/WebPart]
    ]]][/View]

    ReplyDelete
  4. I don't have a ready answer for you, but based on my testing (exporting web part and importing it), you could try having these three properties:

    <FrameState>Minimized</FrameState>
    <ChromeState>Minimized</ChromeState>
    <AllowMinimize>true</AllowMinimize>

    FrameState appears to be obsolete and you should only use ChromeState, but only having ChromeState doesn't work. AllowMinimize must be true in order to be able to minimize web parts. It defaults as true, but it doesn't hurt trying to define it explicitly.

    Also, if this doesn't help, can you try to export a minimized web part and try re-importing it to see if that works. If yes, then there is some issue that is related to onet.xml and minimized web parts.

    ReplyDelete
  5. How do you do this for Sharepoint 2003?
    I tried exactly your code (Except the assembly version is 11), but it doesn't seem to work.

    ReplyDelete
  6. Can you change the list view settings also ?? I mean can you define properties for customized views

    ReplyDelete
  7. Hi,
    could you help me changing the chrometype property to titleandborder for a listview webpart?

    ReplyDelete
  8. Have you tried exporting the web part and seeing how the ChromeType is defined?

    Exporting stuff after modifying them using browser is often a good way to find out how to do things declaratively.

    ReplyDelete
  9. Hey thanks a lot Jussi.. It helped me a lot [:)]

    ReplyDelete
  10. Fantastic! I wish I'd found this years ago - not being able to set the list view title in a Site Def has annoyed me for years!

    ReplyDelete