Skip to main content

Cloud

Use a custom resource file in your SharePoint feature

Problem

You want to use a custom resource file for your Elements.xml file just like the out-of-the-box SharePoint features do.

Assumptions

This post assumes that you are using Visual Studio to develop and deploy your SharePoint feature.

Solution

1.) Create a Resources folder under the 12 folder in your Visual Studio project.

2.) Right-click on the resources folder and select New Item. Add a resource file to your project. Note: It is important that you do not use a resource filename that exists in your SharePoint resources directory.

3.) Add resource key/value pairs for the content that you wish to include in your elements.xml files.

Discussion

When you look at the xml files that are included in the out of the box features of SharePoint, it is easy to notice the use of resource files to fill in the property values for most elements that are defined in the xml files. The format of the resource use is "$Resources:ResourceFilename,ResourceString;"

<File Url="ArticleLinks.aspx" Type="GhostableInLibrary">
<Property Name="Title" Value="$Resources:cmscore,PageLayout_ArticleLinks_Title;" />
<Property Name="MasterPageDescription" Value="$Resources:cmscore,PageLayout_ArticleLinks_Description;" />
<Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
<Property Name="PublishingPreviewImage"
Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/ArticleLinks.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/ArticleLinks.png" />
<Property Name="PublishingAssociatedContentType"
Value=";#$Resources:cmscore,contenttype_articlepage_name;;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D;#"/>
</File>

Using the sample project shown in the screen shots above, an elements entry that uses the custom resource file would look like:

<Proptery Name="Title" Value="$Resources:Sample,MyContentTypeName;" />

Leave a Reply

Your email address will not be published. Required fields are marked *

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

PointBridge Blogs

More from this Author

Follow Us
TwitterLinkedinFacebookYoutubeInstagram