skip to Main Content

Provisioning List Views in the onet.xml with custom Web Part properties

I’ve seen this come up numerous times (with a few people telling me “it’s not possible without writing code”) so I thought I’d show a simple code sample of how this is done in SharePoint 2013.

Let’s say you want to add some List View Web Parts to a custom Team Site for a Tasks list:

  • My Tasks
  • Tasks In Progress
  • Tasks Overdue

You would initially do this kind of thing in your onet.xml:

<View List="Lists/Tasks" BaseViewID="1" WebPartZoneID="Header" />
<View List="Lists/Tasks" BaseViewID="2" WebPartZoneID="Header" />
<View List="Lists/Tasks" BaseViewID="3" WebPartZoneID="Header" />

Of course the main problem here is that you have zero control over any of the Web Part properties (such as the Title, border, or anything else). The default title will use the same title as the list, which of course (when you have the same list more than once) offers the stunningly un-useful:

  • Tasks (1)
  • Tasks (2)
  • Tasks (3)

The solution is to include some additional Web Part properties in embedded CDATA tags:

Embedding Sandbox Web Parts Clip Image002

This gives you effectively complete control over any of the Web Part Properties (see XsltListViewWebPart Properties).

Happy coding!

By Martin Hatch, Associate Principal SharePoint Consultant
www.martinhatch.com

Have a comment? Let us know below, or send an email to [email protected]

About the Author

Our technical team contribute with blogs from their respective specialities, be that Azure, SQL, BizTalk, SharePoint, Xamarin and more. From the lead architect to developers and testers, each person provides content straight from their experience.

Previous Post
Next Post
Back To Top
Contact us for a chat