SharePoint: Set a SummaryLink Column Value using a Feature Module


Both the SummaryLink column and the SummaryLink webparts allow the user to store arbitrary URL’s either on a page in a webpart or in a page column, and both of these components are well documented in terms of styling and exercising them using the object model. 

What isn’t well documented (at least not that I could find) is how to populate the the field value of a SummaryLink column for a publishing or non-publishing page using a feature module File element.

I started with the a SummaryLinks webpart, populated some links and exported the webpart, looking through the exported XML I noticed a property value called “SummaryLinkStore” which contained some HTML encoded content;

<property name="SummaryLinkStore" type="string">
 &lt;div title="_schemaversion" id="_3"&gt;
 &lt;div title="_links"&gt;
 &lt;div title="_link"&gt;
 &lt;span title="_title"&gt;Link 1&lt;/span&gt;
 &lt;span title="_order"&gt;1&lt;/span&gt;
 &lt;span title="_begincolumn"&gt;True&lt;/span&gt;
 &lt;span title="_linkurl"&gt;
 &lt;a href="http://www.google.com"&gt;http://www.google.com&lt;/a&gt;
 &lt;/span&gt;
 &lt;span title="_style"&gt;Item_bulleted&lt;/span&gt;
 &lt;/div&gt;
 &lt;div title="_link"&gt;
 &lt;span title="_title"&gt;Link 2&lt;/span&gt;
 &lt;span title="_order"&gt;2&lt;/span&gt;
 &lt;span title="_begincolumn"&gt;False&lt;/span&gt;
 &lt;span title="_linkurl"&gt;
 &lt;a href="http://www.google.com"&gt;http://www.google.com&lt;/a&gt;
 &lt;/span&gt;
 &lt;span title="_style"&gt;Item_bulleted&lt;/span&gt;
 &lt;/div&gt;
 &lt;/div&gt;
 &lt;div title="_view"&gt;
 &lt;span title="_columns"&gt;1&lt;/span&gt;
 &lt;span title="_linkstyle"&gt;Item_bulleted&lt;/span&gt;
 &lt;span title="_groupstyle"&gt;DefaultHeader&lt;/span&gt;
 &lt;/div&gt;
 &lt;/div&gt;
</property>

After decoding this, it revealed some well formed (in XML terms) HTML markup which described the populated links;

<div title="_schemaversion" id="_3">
    <div title="_links">
        <div title="_link">
            <span title="_title">Link Title 1</span>
            <span title="_order">1</span>
            <span title="_begincolumn">True</span>
            <span title="_linkurl">
                <a href="http://www.link1.com">http://www.link1.com</a>
            </span>
            <span title="_linktooltip">link 1 tooltip</span>
            <span title="_style">Item_bulleted</span>
            <span title="_openinnewwindow">True</span>
        </div>
        <div title="_link">
            <span title="_title">Link 2</span>
            <span title="_order">2</span>
            <span title="_begincolumn">False</span>
            <span title="_linkurl">
                <a href="http://www.link2.com">http://www.link2.com</a>
            </span>
            <span title="_linktooltip">link 2 tooltip</span>
            <span title="_style">Item_bulleted</span>
        </div>
    </div>
    <div title="_view">
        <span title="_columns">1</span>
        <span title="_linkstyle">Item_bulleted</span>
        <span title="_groupstyle">DefaultHeader</span>
    </div>
</div>

The schema shown above works for both the SummaryLink column and the SummaryLink webpart, and fortunately the HTML markup does seem to be consistently well formed, so (if for some reason you wanted to) you could parse this with an Xml parser (XPathNavigator/XmlDocument).

So to populate the value of a SummaryLink column using a File element in a feature module, create the links HTML markup as above, HTML encode it and place the encoded markup in a property statement in your File element;

<File Url="MyPage.aspx" Type="GhostableInLibrary" Path="template.aspx" IgnoreIfAlreadyExists="TRUE">
<Property Name="Title" Value="Page Title" />
<Property Name="ContentType" Value="......" />
<Property Name="PublishingPageLayout" Value="......." />
<Property Name="MySummaryLinkColumn" Value="&lt;div title=&quot;_schemaversion&quot; id=&quot;_3&quot;&gt ........ &lt;/div&gt;&lt;/div&gt;" />
</File>

 

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.