Thursday, May 31, 2012

Default page and Default Page Layout of a Custom Site Template

When we create a site based on one of the SharePoint site templates and visit the site, usual behavior is to automatically redirect to the default.aspx page of the new site. (<NewSiteURL>/Pages/default.aspx), which is sometimes not what we want. When creating custom site templates we can change this behavior in the SharePoint Server Publishing feature as this default page is created automatically by publishing feature.

Set about-us.aspx as the Default page (Welcome page)

Create a new module for the custom default page like shown below and put the about-us.aspx page beside the default.aspx in the SiteTemplate folder.

<Module Name="AboutUs" Url="$Resources:osrvcore,List_Pages_UrlName;" Path="">
  <File Url=" about-us.aspx " Type="GhostableInLibrary" >
    <Property Name="Title" Value="AboutUs" />
    <Property Name="Comments" Value="About Us Page" />
    <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/PageLayout1.aspx, PageLayout 01 Title" />
    <Property Name="ContentType" Value="My Article Page" />
  </File>
</Module>


Then set WelcomePageUrl property in the Publishing feature as below.

<Property Key="WelcomePageUrl" Value="$Resources:osrvcore,List_Pages_UrlName;/about-us.aspx"/>


Set PageLayout1.aspx as the Default PageLayout

Use DefaultPageLayout property in the Publishing feature as below.

<Property Key="DefaultPageLayout" Value="~SiteCollection/_catalogs/masterpage/PageLayout1.aspx"/>


So the publishing feature with a custom default page and a custom default Page Layout will look like this.

<!--Publishing feature-->
<Feature ID="22A9EF51-737B-4ff2-9346-694633FE4416">
  <Properties xmlns="http://schemas.microsoft.com/sharepoint/">
    <Property Key="ChromeMasterUrl" Value="~SiteCollection/_catalogs/masterpage/MyAboutUs.master"/>
    <Property Key="WelcomePageUrl" Value="$Resources:osrvcore,List_Pages_UrlName;/about-us.aspx"/>
    <Property Key="SimplePublishing" Value="false" />
    <Property Key="DefaultPageLayout" Value="~SiteCollection/_catalogs/masterpage/PageLayout1.aspx"/>
  </Properties>
</Feature>

Wednesday, May 23, 2012

Access Lists in Variation TobWeb

I’m working on a SharePoint project that uses the Variations feature to support multiple languages in regions. Basically I have a Global site (A SP Site Collection) which supports only English so does not have variations setup and I have a set of Regional sites (Again SP Site Collections), where the variations are set up and supports multiple languages.


















Most of the Webparts I implement will be reused in both Global site as well as in Regional sites. One such Webpart is Footer Links control, which will read data from a SP List called FooterLinksList. When in one of the Regional sites, the FooterLinksList reside in the top level site of the variation. This requirement came because of the footer links are region specific as well as language specific. When in the Global site the FooterLinksList reside in the root level of the site collection.
Now the complication is we cannot use SPContext.Current.Site.RootWeb to access list instance since in regional sites, list instances resides one level below the root level. Also we cannot use SPContext.Current.Web to access list instance since 3rd or 4th level sub-sites in the variations does not have the FooterLinksList list instance.
So the solution was to have a common function to find the top site. In case of Global, it is the root web, in case of Regional; it is the Variation Top Site.
/// <summary>
/// Get the top Site - SPWeb having all the list instances.
/// </summary>
/// <returns>The top SPWeb</returns>
[method: CLSCompliant(false)]
public static SPWeb GetTopSite()
{
  string currentUrl = SPContext.Current.Web.Url;
  ReadOnlyCollection<VariationLabel> variationLabels = Variations.Current.UserAccessibleLabels;

  foreach (VariationLabel vl in variationLabels)
  {
    if (currentUrl.StartsWith(vl.TopWebUrl, StringComparison.CurrentCultureIgnoreCase))
    {
      Regex urlValue = new Regex(SPContext.Current.Site.Url, RegexOptions.IgnoreCase);
      string sharepointWebToGo = urlValue.Replace(vl.TopWebUrl, string.Empty).Trim('/');
      return SPContext.Current.Site.OpenWeb(sharepointWebToGo);
    }
  }
  // When in the Global site.
  return SPContext.Current.Site.OpenWeb();
}


Here note that in order to simplify the usage of this method, I used SPContext.Current.Site.OpenWeb() instead of SPContext.Current.Site.RootWeb. So I can dispose the SPWeb object as below.

using (SPWeb web = Utility.GetTopSite())
{
  if (web != null)
  {
    SPList actionpanellList = web.Lists.TryGetList(ActionItemsListName);
    if (actionpanellList != null)
    {
      // ...
    }
  }
}

Friday, May 11, 2012

Special Characters in SharePoint Top Navigation

When I was creating a custom master page for a SharePoint 2010 site, I ran run into an issue with the top navigation bar since some headings and links had special characters.  When I view the page “Plans & Pricing” was rendered as " Plans &amp; Pricing". That means ampersand shows as &amp; in the global navigation. Also “FAQ’s” was rending as “FAQ&#39;s”.







The solution was to just add EncodeTitle="false" in the AspMenu control.
<!-- ------------| TOP NAVIGATION  |------------ -->
<div class="s4-notdlg">
 <!-- top navigation publishing data source -->
 <SharePoint:AspMenu
   ID="TopNavigationMenuV4"
   Runat="server"
   EnableViewState="false"
   DataSourceID="topSiteMap"
   AccessKey="<%$Resources:wss,navigation_accesskey%>"
   UseSimpleRendering="true"
   UseSeparateCss="false"
   Orientation="Horizontal"
   StaticDisplayLevels="1"
   MaximumDynamicDisplayLevels="1"
   SkipLinkText=""
   EncodeTitle="false"
   CssClass="s4-tn"/>
                       
 <asp:SiteMapDataSource
   ShowStartingNode="False"
   SiteMapProvider="CombinedNavSiteMapProvider"
   id="topSiteMap"
   runat="server"/>
</div>
<!-- ------------| TOP NAVIGATION  |------------ -->


Thursday, May 3, 2012

Variations in SharePoint 2010


The SharePoint Server 2010 variations feature enables site administrators to make the same information available to specific audiences across different sites by maintaining customizable copies of the content from the source variation in each target variation. Variations feature can be used to manage multilingual sites and pages, when you provision a new SharePoint publishing site.

A variation consists of a set of labels that is used to create a set of sites in a site collection. For example, if you want four language variations of your site, you must create four labels, one for each language. Then the labels are instantiated as SharePoint publishing sites and the full set of labels in a site collection is referred to as the Variations Hierarchy.


Steps to Create Variations

1.    From the Site Collection Administration in the Site Settings, select Variations to set variations settings.



















2.    Specify variation home. To indicate the root site of the site collection, type a slash.








 3.    From the Site Collection Administration in the Site Settings, select Variation labels. Use New Label option to create two labels, one for English and one for French. Let’s use English site as the source site. The source site should be the one where most of the new content enters the system. When creating the source site it is possible to use our custom publishing template as the source template. More information on how to bring our custom publishing template into variations drop-down list can be found here.



























Note: in order to select French (or any language other than English) as a site template language, you should install the correct language pack on the server. Language Packs for SharePoint Server 2010 can be found here. When installing language pack give special attention to install instructions, you are required to run SharePoint configuration wizard and re-run the SharePoint Products and Technologies Configuration Wizard with default settings. Otherwise the language pack will not be installed properly.


4.    Once done with creating labels, select Create Hierarchies option. It will invoke the timer job “Variations Create Hierarchies Job Definition” and timer job will be run based on its schedule.












 5.    You can check the timer job in Central Admin and if required, can change the schedule temporarily to shorter time period (5 minutes) to test the variation creation. Go to Monitoring -> Review job definitions and find “Variations Create Hierarchies Job Definition” timer job of your web application.

If the hierarchies created successfully, you can see it in the variation labels listing. Also typing the site URL in browser will take you to the correct variation site \en or \fr.













Custom Publishing Site Templates

If you are using a custom publishing site template and variation site hierarchy is not getting created for sites other than English, following steps might help.

Make sure you have created webtemp files for each of the language that you create variation labels. Webtemp files reside in the TEMPLATE folder of the 14 hive, inside sub-folders created as LocaleID\XML

So the site difinition structure will look like this.












SharePointProjectItem.spdata file of the site definition will look like this.

<?xml version="1.0" encoding="utf-8"?>
<ProjectItem Type="Microsoft.VisualStudio.SharePoint.SiteDefinition" SupportedTrustLevels="FullTrust" SupportedDeploymentScopes="Package" xmlns="http://schemas.microsoft.com/VisualStudio/2010/SharePointTools/SharePointProjectItemModel">
 <Files>
  <ProjectItemFile Source="1033\webtemp_DEPortal.xml" Target="1033\xml\" Type="TemplateFile" />
  <ProjectItemFile Source="1034\webtemp_DEPortal.xml" Target="1034\xml\" Type="TemplateFile" />
  <ProjectItemFile Source="1036\webtemp_DEPortal.xml" Target="1036\xml\" Type="TemplateFile" />
  <ProjectItemFile Source="DEPortalWebManifest.xml" Target="SiteTemplates\WebManifest\" Type="TemplateFile" />
 </Files>
</ProjectItem>

Wednesday, May 2, 2012

Variations in SharePoint 2010 - Bring Custom Publishing Site Definitions into Variations Dropdown

I was trying to set up variations in a SharePoint 2010 environment and my target was to use one of my custom publishing site templates to use for provisioning the source variation site.















Since SharePoint says all the publishing site templates will be listed down in the Source Variation selection, I started with SharePoint default “BlankInternet” site template to create a custom site definition and make sure all the publishing features were enabled by the custom site definition. But the custom site definition was not listed down in the source variations dropdown. The solution I found was, we have to set the FilterCategories="PublishingSiteTemplate" property for the template in webtemp_ xml file as below.

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML\subwebs.xml
<?xml version="1.0" encoding="utf-8" ?>
<portal xmlns="PortalTemplate.xsd">

 <web name="BlankInternet Site"
   siteDefinition="BLANKINTERNET#0"
   displayName="BlankInternet Site"
   description="It has no subwebs" >

 </web>
</portal>

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\1033\XML\webtempSUBWEBS.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- _lcid="1033" _version="12.0.4518" _dal="1" -->
<!-- _LocalBinding -->

<Templates xmlns:ows="Microsoft SharePoint"> ;
 <Template Name="SUBWEBS" ID="84529">

  <Configuration
   ID="0"
   Title="Publishing Site with no sub webs"
   Hidden="FALSE"
   ImageUrl="/_layouts/images/officialfile.jpg"
   Description="This template creates a BLANKINTERNET site"
   ProvisionAssembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
   ProvisionClass="Microsoft.SharePoint.Publishing.PortalProvisioningProvider"
   ProvisionData="xml\\subwebs.xml"
   DisplayCategory="Custom"
   FilterCategories="PublishingSiteTemplate"
   VisibilityFeatureDependency="97A2485F-EF4B-401f-9167-FA4FE177C6F6">
  </Configuration>

 </Template>
</Templates>


Once done, “Publishing Site with no sub webs” template can be seen in the source variations dropdown list.