The Latest Time Saving Tips for Your SharePoint Deployment

Corey Roth

Subscribe to Corey Roth: eMailAlertsEmail Alerts
Get Corey Roth via: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

Related Topics: Intel XML, XML Magazine, SharePoint Archiving Journal, Microsoft Developer, CIO/CTO Update

Blog Feed Post

Using PropertyBag Element to Assign Properties to Items in SharePoint 2010

When the NDA dropped, I mentioned how you could use the new PropertyBag element in a feature to write values

SharePoint Archiving Journal on Ulitzer

When the NDA dropped, I mentioned how you could use the new PropertyBag element in a feature to write values into the property bag of a site.  I already thought that was going to be incredibly useful, but it turns out the power of this new element is even greater than I first realized.  At the time I noticed that the PropertyBag element had a Url attribute but I didn’t understand what it was used for at the time.  Now I do.  As I mentioned yesterday, I have been experimenting with exporting sites as .wsp files and I discovered that you can use this to write to properties of an existing list item.  Take a look at the following example, that I grabbed from the file it generated when exporting my site.  This applies properties to default.master.

<?xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<PropertyBag Url="_catalogs/masterpage/default.master" ParentType="File" RootWebOnly="FALSE" HyperlinkBaseUrl="http://sp2010/Test" xmlns="http://schemas.microsoft.com/sharepoint/">

<Property Name="vti_charset" Value="utf-8" />

<Property Name="vti_candeleteversion" Value="true" />

<Property Name="vti_modifiedby" Value="SHAREPOINT\system" />

<Property Name="vti_cachedneedsrewrite" Value="false" />

<Property Name="vti_level" Value="1" />

<Property Name="vti_rtag" Value="rt:7CDE768C-FCE1-46E8-9165-FDA564419D9A@00000000002" />

<Property Name="vti_cachedbodystyle" Value="&lt;body scroll=&quot;yes&quot; onload=&quot;BLOCKED SCRIPTif (typeof(_spBodyOnLoadWrapper) != 'undefined') _spBodyOnLoadWrapper();&quot;&gt;" />

<Property Name="vti_title" Value="&lt;asp:ContentPlaceHolder id=&quot;PlaceHolderPageTitle&quot; runat=&quot;server&quot;/&gt;" />

<Property Name="UIVersion" Value="3" />

<Property Name="vti_parserversion" Value="" />

<Property Name="vti_cachedhastheme" Value="false" />

<Property Name="vti_foldersubfolderitemcount" Value="0" />

<Property Name="vti_hasdefaultcontent" Value="true" />

<Property Name="vti_setuppathversion" Value="4" />

<Property Name="vti_metainfoversion" Value="2" />

<Property Name="vti_canmaybeedit" Value="true" />

<Property Name="vti_generator" Value="Microsoft SharePoint" />

<Property Name="vti_etag" Value="&quot;{7CDE768C-FCE1-46E8-9165-FDA564419D9A},2&quot;" />

<Property Name="vti_cachedtitle" Value="&lt;asp:ContentPlaceHolder id=&quot;PlaceHolderPageTitle&quot; runat=&quot;server&quot;/&gt;" />

<Property Name="vti_contentversion" Value="0" />

<Property Name="vti_progid" Value="SharePoint.WebPartPage.Document" />

<Property Name="vti_timelastmodified" Value="2010-02-10T16:12:34Z" />

<Property Name="vti_sourcecontrolversion" Value="V1.0" />

<Property Name="vti_timecreated" Value="2010-02-10T16:12:34Z" />

<Property Name="vti_folderitemcount" Value="0" />

<Property Name="vti_docstoretype" Value="0" />

<Property Name="ContentTypeId" Value="0x01010500CE60EDAC92E8C942BFB82AF8AFC4A5F4" />

<Property Name="vti_filesize" Value="29039" />

<Property Name="vti_sourcecontrolcookie" Value="fp_internal" />

<Property Name="vti_author" Value="SHAREPOINT\system" />

<Property Name="vti_setuppath" Value="global\default.master" />

<Property Name="vti_metatags" Value="GENERATOR Microsoft\ SharePoint progid SharePoint.WebPartPage.Document HTTP-EQUIV=Content-Type text/html;\ charset=utf-8 HTTP-EQUIV=Expires 0" />

<Property Name="vti_replid" Value="rid:{7CDE768C-FCE1-46E8-9165-FDA564419D9A}" />

<Property Name="vti_docstoreversion" Value="2" />

<Property Name="vti_cachedcustomprops" Value="vti_title" />



As you can see the relative URL of the file is specified along with a separate attribute indicating the base URL it came from.  You also need to specify something for ParentType.  For now I know that you can specify File or Folder there (although I am guessing it might take Item or something like that).

Now for the most part all of these properties listed above are internal properties that you would never care about setting, but as you guessed you can specify your own properties as well.  The export site as template functionality does its best to export everything it can and that includes internal properties as well.  This is pretty interesting feature and I think it could remove the need to write a lot of code in my future.  @SPKyle might still want to write code to store properties on list items, but I will take a pass. :)

Read the original blog entry...

More Stories By Corey Roth

Corey Roth, a SharePoint Server MVP, is an independent consultant specializing in Cloud technologies such as Azure and Office 365. He also specializes in mobile development. Corey serves as the product manager for two cloud-first mobile app platforms: BrewZap and HappenZap.