ballardchalmers - home

Contact us 01342 410223

Blog

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 enquiries@ballardchalmers.com

Comment on this article

About

Ballard Chalmers is one of the UK’s leading enterprise software engineering companies, specialising in development for the Microsoft Enterprise Application Platform. We are principally dedicated to software development and integration for the Microsoft Cloud, as well as on-premises and hybrid systems. Our expertise is in Microsoft .NET, SQL Server, BizTalk Server and SharePoint Server.

Let's talk

  01342 410223

Find out more

Thank you for contacting us.

We will be in touch with you shortly.