SharePoint MUI Resource files

11. May 2011 06:16 by arnoldbo in SharePoint  //  Tags: ,   //   Comments

In SharePoint 2010 you have the ability to configure alternate languages for a website, this feature enables that navigation and labels are presented in the user selected language without creating variations, when on a farm multiple language pack’s are deployed you can configure Alternate Languages on every site.

Configure Multilangual User Interface

1. goto site settings –> Language Settings

 

image

2. select the languages of choise.

3. press OK to save changes.

 

Change Language on Site

The language of the current site can be changed by slecting the ‘Select Display Language’ in the user menu

image

Using Labels in your solution

When you want to use different languages in your custom solutions it is possible to make use of resource files withing SharePoint.

The SharePoint object model provides Helper methods to get localized strings, the following article on MSDN explains how to use this: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility.getlocalizedstring.aspx

 

Get current language of user

With SPWeb.Language you get the ‘default’ language of the site in the case of alternate languages it is not sufficient to use this because a user could have set the language to a non ‘default’ language.

 

The current language of a user can be found at: CultureInfo.CurrentUICulture.LCID

 

The following Helper method can be used to retrieve localized strings with respect to the user selected language.

 

public static string GetResourceString(string resourceName, string name)
{
    int languageId = 1033;
    if (SPContext.Current != null && SPContext.Current.Web != null)
    {
        //Set Language to default language of web object! languageId = (int)SPContext.Current.Web.Language; 
   
        //if alternate language is selected by user! if (SPContext.Current.Web.IsMultilingual &&
            SPContext.Current.Web.SupportedUICultures.Where(w => w.LCID == CultureInfo.CurrentUICulture.LCID).
                Any())
        {
            languageId = CultureInfo.CurrentUICulture.LCID;
        }
    }
    return SPUtility.GetLocalizedString(resourceName, name, (uint)languageId);
}

Upgrade localized SharePoint 2007 Publishing site to SharePoint 2010

22. February 2011 06:09 by arnoldbo in SharePoint  //  Tags: , ,   //   Comments

publishing_error

 

Update: March 11 2011

Microsoft KB2484317 for issue with solution

 

http://support.microsoft.com/kb/2484317

 

After a succesfull (according to upgrade log file) upgrade of a SharePoint 2007 localized publishing site, the site is not working, the following error occurs when accessing the portal:

 

Ongeldig SPListItem. Het opgegeven SPListItem is niet compatibel met een publicatiepagina.

[ArgumentException: Ongeldig SPListItem. Het opgegeven SPListItem is niet compatibel met een publicatiepagina.]
Microsoft.SharePoint.Publishing.PublishingPage.GetPublishingPage(SPListItem sourceListItem) +303
Microsoft.SharePoint.Publishing.Internal.WebControls.PublishingPageStateControl.RaisePostBackEventForPageRouting(String eventArgument, SPRibbonCommandHandler control, RaisePostBackEventDelegate raisePostBackEventDelegate) +110
Microsoft.SharePoint.Publishing.Internal.WebControls.PublishingPageSaveAndStopEditHandler.RaisePostBackEvent(String eventArgument) +134
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

 

The same message in English:

"Invalid SPListItem. The SPListItem provided is not compatible with a Publishing Page."

 

 

Problem

Publishing sites in SharePoint 2007 has a default location for the publishing pages at ‘/Pages/’ in SharePoint 2010 the location has a new name in the Dutch Language pack of ‘/Paginas/’

 

The change has been made in the following resource file: osrvcore.nl-NL.resx

 

<Data Name="List_Pages_UrlName">
  <Value>Paginas</Value>
</Data>

 

Quick Solution

This is not a real solution but this proves that the real solution solves the problem.

 

Step 1: change in the osrvcore.nl-NL.resx the following lines:

 

<Data Name="List_Pages_UrlName">
<Value>Paginas</Value>
</Data>

 

by:

<Data Name="List_Pages_UrlName">
<Value>Pages</Value>
</Data>

 

Warning: it is not supported to change the default resource files.

 

After saving the file and performing an IISreset the site is working with no problems, now we know this we can solve the issue in a more robust way by moving the ‘Pages’ to ‘Paginas’ location.

 

Real Solution

After upgrading localized publishing sites the following steps needs to be performed:

 

Step 1: Move your publishing pages inside the pages library to ‘Paginas’

Create a console application an perform following code on the server, the same can be accomplished by writing a PowerShell script. In this example I know that I only need to change Dutch sites (1043).

 

using (SPSite sitecollection = new SPSite(sitecollectionUrl))
{
    foreach (SPWeb web in sitecollection.AllWebs)
    {
        //Dutch language if (web.Language == 1043)
        {
            foreach (SPList item in web.Lists)
            {
                if (item.RootFolder.Url == "Pages")
                {
                    item.RootFolder.MoveTo(item.RootFolder.Url.Replace("Pages", "Paginas"));
                    item.Update();
                }
            }
        }
    }
}

Step 2: Set the welcomepage location to the new default.aspx

Execute the following code on the server through a console app.

 

using (SPSite sitecollection = new SPSite(sitecollectionUrl))
{
    foreach (SPWeb web in sitecollection.AllWebs)
    {
if (web.Language == 1043)
        {
            if (PublishingWeb.IsPublishingWeb(web))
            {
                PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
                SPFile welcomePage = null;
                welcomePage = web.GetFile("Paginas/default.aspx");

                if (welcomePage != null)
                {
//Set default welcomepage
                    publishingWeb.DefaultPage = welcomePage;
                    publishingWeb.Update();
                }
            }        
        }
    }
}

Step 3: reactivate publishing feature for each site.

In this situation we only had a couple of subsites so we manually disabled and activated the feature for each sub site.

 

publishing_feature

SharePoint 2010 Global List Id’s

29. January 2011 23:55 by arnoldbo in SharePoint  //  Tags:   //   Comments

defaultlists

 

Recently I needed to know the List id of the Theme’s list and wasn’t able to find a list on MSDN so I looked @ the SharePoint root to find out.

 

The SharePoint 2010 Global lists can be found @ “{SharePointRoot}\TEMPLATE\GLOBAL\Lists”, the following list definition’s are available.

 

All these lists are provisioned from the Global ONET.xml (“{SharePointRoot}\TEMPLATE\GLOBAL\XML\ONET.xml”) while creating a new Site collection.

 

 

Internal Name Name Description Id

solutions

Solution Gallery Place to store Solutions 121

mplib   

Master Page Gallery Place to store Master Pages 116

users   

User Information List All users within the site collection 112

webtemp 

Site Template Gallery Gallery for storing custom site designs 111

wplib   

Web Part Gallery Gallery for storing web part definitions 113

listtemp 
 

List Template Gallery Make a template available for use in list creation by adding to this gallery. Default list templates are not shown 114

themes

Theme Gallery Use the theme gallery to store themes. The themes in this gallery can be used by this site or any of its subsites. 123

Provision publishing page with webpart in sandboxed solution

17. August 2010 19:59 by arnoldbo in SharePoint  //  Tags: ,   //   Comments
 

While working with Sandboxed solutions in SharePoint 2010 I faced a problem with attaching a webpart to a publishing page.

The code I used for deploying a page:

   1: <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   2:   <Module Name="PageInstance"
   3:         Url="Pages"
   4:         Path="PageInstance">
   5:  
   6:     <File Url="test.aspx" Path="default.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE">
   7:       <Property Name="Title" Value="Test Title" />
   8:       <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/customLayout.aspx, My Custom Layout" />
   9:       <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
  10:       <Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/ArticleLinks.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/ArticleLinks.png" />
  11:       <Property Name="PublishingAssociatedContentType" Value=";#CustomLayout - CustomPages;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D00AC43246F7BB54A1389CAF0BEC1C1AEE4;#"/>
  12:       <AllUsersWebPart WebPartOrder="1" WebPartZoneID="Main">
  13:       <![CDATA[
  14:       <webParts>
  15:         <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
  16:           <metaData>
  17:             <type name="CustomLayout.SandboxedVisualWebPart1.SandboxedVisualWebPart1, CustomLayout, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9242a569ebe2d353" />
  18:             <importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
  19:             <Solution SolutionId="245ba111-9620-424c-9a8f-9eceaa2d33c6" xmlns="http://schemas.microsoft.com/sharepoint/" />
  20:           </metaData>
  21:           <data>
  22:             <properties>
  23:               <property name="Title" type="string">SandboxedVisualWebPart1</property>
  24:               <property name="Description" type="string">My custom sandbox web part</property>
  25:             </properties>
  26:           </data>
  27:         </webPart>
  28:       </webParts>     
  29:       ]]>
  30:       </AllUsersWebPart>
  31:     </File>
  32:   </Module>
  33: </Elements>

The problems with this in a sandboxed solution are:

1. Approval state is set to draft

2. Webpart is not deployed

I realized that there is a good reason that there are problems using this approach because SharePoint will try to load “default.aspx” which is stored in the “SharePoint Root\TEMPLATE\FEATURES\FEATURENAME folder, and Sandbox Solutions doesn’t have access to the SharePoint root.

 
 

On MSDN I found that a module element accepts the “SetupPath” property (http://msdn.microsoft.com/en-us/library/ms460356.aspx) now I rewrote my feature with the “SetupPath” property.

   1: <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   2:   <Module Name="PageInstance"
   3:         Url="Pages"
   4:         SetupPath="SiteTemplates\SPS"> <!-- Important for sandboxed solution!!! path in file element is using this path for finding location -->
   5:  
   6:     <File Url="test.aspx" Path="default.aspx" Type="GhostableInLibrary" IgnoreIfAlreadyExists="TRUE">
   7:       <Property Name="Title" Value="Test Title" />
   8:       <Property Name="PublishingPageLayout" Value="~SiteCollection/_catalogs/masterpage/customLayout.aspx, My Custom Layout" />
   9:       <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
  10:       <Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/ArticleLinks.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/ArticleLinks.png" />
  11:       <Property Name="PublishingAssociatedContentType" Value=";#CustomLayout - CustomPages;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D00AC43246F7BB54A1389CAF0BEC1C1AEE4;#"/>
  12:       <AllUsersWebPart WebPartOrder="1" WebPartZoneID="Main">
  13:       <![CDATA[
  14:       <webParts>
  15:         <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
  16:           <metaData>
  17:             <type name="CustomLayout.SandboxedVisualWebPart1.SandboxedVisualWebPart1, CustomLayout, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9242a569ebe2d353" />
  18:             <importErrorMessage>$Resources:core,ImportErrorMessage;</importErrorMessage>
  19:             <Solution SolutionId="245ba111-9620-424c-9a8f-9eceaa2d33c6" xmlns="http://schemas.microsoft.com/sharepoint/" />
  20:           </metaData>
  21:           <data>
  22:             <properties>
  23:               <property name="Title" type="string">SandboxedVisualWebPart1</property>
  24:               <property name="Description" type="string">My custom sandbox web part</property>
  25:             </properties>
  26:           </data>
  27:         </webPart>
  28:       </webParts>     
  29:       ]]>
  30:       </AllUsersWebPart>
  31:     </File>
  32:   </Module>

 

At this point Path=”default.aspx” is pointing to the physic location: “SharePoint Root\TEMPLATE\SiteTemplates\SPS\default.apx”, so the “default.aspx” file in the module can be removed.

The file “default.aspx” as a template file for a publishing page.

After deploying the feature with this module the state of the page is Approved and the Webpart is available on the page.