Putting Custom Web Parts in ONET.xml

So yesterday I was trying to add a content editor webpart to a page I was deploying through ONET.XML. I wondered how to add custom web parts, and how you’d know what the XML for them was.

Turns out it isn’t very hard. An example:

<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="SourceCode.Solutions.GenericCaseWebParts.CaseSSRSReportViewer" />
<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="TitleUrl" type="string" />
<property name="TitleIconImageUrl" type="string" />
<property name="ReportServerUrl" type="string">http://vm-moss:8088/ReportServer</property&gt;
<property name="Parameters" type="string">&lt;ReportParameters&gt;&lt;Parameter Name="CaseId" MultiValue="false" Value="[Case Id]" /&gt;&lt;/ReportParameters&gt;</property>
<property name="ChromeState" type="chromestate">Normal</property>
<property name="Title" type="string">Context Info</property>
<property name="ReportPath" type="string">/Reports/Case Details</property>
<!-- Snip -->
</properties>
</data>
</webPart>
</webParts>

As you can see, at the top we define the class to use, then we set various properties (I’ve trimmed that set quite a lot). But how did I get the XML? Well… I set the web part up in SharePoint and exported the web part to a file; this was the XML I needed to put into my ONET.xml. Copy and paste… job done.

Putting Custom Web Parts in ONET.xml

Putting CEWP into a page in ONET.XML

When you provision sites you can provide various pages (normal pages, not just publishing ones!) However, what if you want to put web parts onto those pages?

Well, you could build multiple pages for your different site configurations. Or you could use a feature receiver to add it programmatically. Or, you could add it via your site configuration. Continue reading “Putting CEWP into a page in ONET.XML”

Putting CEWP into a page in ONET.XML