Tuesday, March 26, 2013

PowerShell Script to Enable Alternate Language(s) in SharePoint 2010

MUI setting is a web level setting and it cannot be set in the site collection level. Therefore enable multilingual user interface manually for a big site collection is a tedious job. (More information on Alternate Language(s) in SharePoint 2010 ishere.)

Following PowerShell script automates the task by setting SPWeb.IsMultilingual property in the specified Web and in it’s all sub Webs. In addition it checks for the installed languages on the server farm and add them to the list of alternative languages supported by the website's multilingual user interface.

# Enable alternate English language for all sub-sites
function EnableAlternateLanguageForAllSubWebs([Microsoft.SharePoint.SPWeb] $web)
{
  $installed = [Microsoft.SharePoint.SPRegionalSettings]::GlobalInstalledLanguages
  $subwebs = $web.GetSubwebsForCurrentUser()
  foreach($subweb in $subwebs)
  {
    $subweb.IsMultiLingual = $true;
    $supportedCultures = $subweb.SupportedUICultures;
    foreach ($lang in $installed)
    {
      $cultureinfo = [System.Globalization.CultureInfo]::GetCultureInfo($lang.LCID);
      $exists = $supportedCultures | Where-Object{$_.LCID -eq $lang.LCID}
      if ($exists -eq $null)
      {
        $subweb.AddSupportedUICulture($cultureinfo)
        Write-Host "Added" $cultureinfo.Name "to URL" $subweb.Url
      }
    }
    $subweb.Update()
  }
}

$web = Get-SPWeb "http://ca.nav.com/texas/"
$DebugPreference = "Continue"

If ($web -ne $null)
{
    EnableAlternateLanguageForAllSubWebs $web
}

It should be noted that exception will be thrown, if the SPWeb.IsMultilingual property is set to ‘true’ on a website where;
  • Website has customized CSS files. 
  • Website based on a template that does not support a multilingual user interface.
Note:
C# script for adding alternate language support is illustrated in the MSDN in article: Understandingthe Multilingual User Interface here.

Monday, March 25, 2013

Alternate language(s) in SharePoint 2010

Alternate languages feature (also called Multilingual User Interface - MUI) in SharePoint 2010 allows a logged on user to change the language to one of the supported alternate languages configured by the site administrator. Therefore with Alternate languages configured, when a user accesses a page, the language actually used will depend on the preferred language in user's browser. So if browser's preferred language is English, we can see 'lang="en-us"' in the page source.


When user switch between languages, following UI elements will be translated (but not site content):
  • Ribbon
  • Site Actions Menu
  • Site Settings Page
  • Lists and Site Column headers
  • Quick Launch Menu
  • Certain Messages displayed in out of the box Webparts
Configure alternate languages:
1. Install required language packs.

2. Go to Site Settings -> Language settings under Site Administration (Language settings option will not be shown if the language packs are not installed.)

3. Based on the language packs installed, we can see a list of languages in Language settings page under Alternative Language(s) section. Select required languages.


4. That’s it. Now a logged on user can switch between languages and UI elements will be translated accordingly.


5. Once the alternative languages selected, there will be two new options coming in the Site Settings page of the site under Site Administration section. Export Translations and Import Translations.


Site administrator can use Export Translations page to export the resource file of a specified language.


Then the translations can be changed as required and translated resource files can be imported back to the site using Import Translations option.

Friday, March 8, 2013

Create an E-mail Distribution Group – SharePoint 2010

Setting up email distribution group allows us to send email to members of a SharePoint group. By default E-Mail Distribution List option is not available in Group Settings section of the groups.

Therefore in order to setup Distribution Emails, first we need to configure incoming email settings in the central administration.


In there we can enable distribution group creation by going with following selection.
  • Select Yes for ‘Use the SharePoint Directory Management Service to create distribution groups and contacts?’ option.
  • Then select Yes for ‘Allow creation of distribution groups from SharePoint sites?’ option.

That’s it! If we navigate to site collection root web, E-Mail Distribution List section will appear in permission group settings.

Navigate Site Settings -> Site Permissions. For each required user group, navigate to Group Settings.


Under E-Mail Distribution List, select Yes for create an e-mail distribution group option and provide the email address for the distribution group created in the active directory.


Note: All necessary Distribution groups should have being created in the active directory and proper email addresses should have being obtained to follow above steps. Also Outgoing E-mail should be configured on each required web application.

Tuesday, February 19, 2013

User Friendly System Maintenance Page - app_offline.htm

app_offline.htm is a special static html page in ASP.NET, which we only copy to IIS root folder when we need to bring down a web site for maintenance. app_offline.htm works for SharePoint too.

1. Create an html page with the name “app_offline.htm”.
2. Make sure file size is more than 512 bytes.
3. Copy to the IIS Root folder.


As long as “app_offline.htm”. file exists in the IIS root, no requests will be processed. Trying to access any page will output app_offline.htm content.


In order to end the maintenance activity, just delete app_offline.htm in IIS root folder.

app_offline.htm file can contain HTML, CSS and JavaScript code but no ASP.NET. Also references to any other files in the directory will not work including images.

Adding Images to app_offline.htm
In order to add an image to the app_offline.htm, use base64 encoding of the image. (Convert any image into a base64 string here)


Note: However I experienced that big images were not rendering. There were no errors but image just not loading.

Monday, February 11, 2013

SharePoint Content Deployment Error - Cannot open file .webpart

I was getting this error “Cannot open file myOldWebpart.webpart” during SharePoint 2010 content deployment job run. The webpart it was given is one of the old webparts I used some time ago but renamed later. So I was wondering whether there are any references left for this old webpart in the content database.

Therefore I used following SQL query to discover any location references for the myOldWebpart.webpart file in content database.

USE  [My-Content-DB]
SELECT DirName, LeafName
FROM [dbo].[AllDocs]
WHERE LeafName = 'myOldWebpart.webpart'

Query result showed that there is a reference in the Web Part Gallery (_catalogs/wp). Since it was the only reference, removing myOldWebpart.webpart file from the webpart gallery fixed my error.

Note:
To prevent such issue happening, it is recommended to write code in the FeatureDeactivating event handler to delete all the webpart template files that were created during feature activation.

Here is a sample code to enumerate through the Web Part Gallery looking for the first part of the webpart file name to delete.

/// <summary>
/// Occurs when a Feature is deactivated.
/// </summary>
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
    SPSite site = properties.Feature.Parent as SPSite;
    SPWeb web = site.RootWeb;

    List<SPFile> filesToDelete = new List<SPFile>();
    SPList webpartGallery = web.Lists["Web Part Gallery"];

    foreach (SPListItem webpartFile in webpartGallery.Items)
    {
        if (webpartFile.File.Name.Contains("myWebpart"))
        {
            filesToDelete.Add(webpartFile.File);
        }
    }

    // Delete .webpart files
    foreach (SPFile file in filesToDelete)
    {
        file.Delete();
    }           
}

However above method will not help if we uninstall the solution package without deactivating the feature. In that case we have to check .webpart file in the Web Part Gallery and have to delete it manually.