Wednesday, April 17, 2013

Custom Action Link in Site Settings – SharePoint 2010

SharePoint does not have an event handler firing on web updates. There are event receivers for WebMoving/ WebMoved, but they won’t fire on events like web title update. Therefore one option to perform some action after updating particular properties in web is to have a custom link in the site settings page of the web.

For example let’s say we want to update the titles for rest of the alternative language sites after changing the title of one of the webs. We can simply have a custom action in the site settings screen.


We can implement the action as clicking on this link will redirect the user to a _Layouts page where we have our custom code implemented to perform the required task.


This custom action can be created using an empty SharePoint element deployed by a feature.


Below is the elements.xml file for the Element. Here “GroupId” specifies the group in site settings page where the link should appear. Here is a list of the default custom action group IDs in MSDN. It is also possible to add a custom group in the site settings page. Here is the CustomActionGroup Element definition in MSDN. “UrlAction Url” specifies the _layouts page consisting of our custom code, while “Rights” specifies the set of rights that the user must have for the link to be visible. If this optional property is not specified, the action always appears in the list of actions.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <CustomAction
    Id="TitleAlternateLanguages"
    GroupId="Customization"
    Location="Microsoft.SharePoint.SiteSettings"
    Title="Title - Alternate Languages"
    Rights="ManageWeb"
    Sequence="41">
    <UrlAction Url="_layouts/AlternativeLanguages/prjaltlansetng.aspx"/>
  </CustomAction>

</Elements>

Tuesday, April 16, 2013

Hide Forms Pages from Anonymous Users – SharePoint 2010

When we enable anonymous access in a SharePoint Publishing site, SharePoint Forms pages are also accessible to anonymous users. That means users can browse pages library, content in custom lists, etc. If the website is a public facing site, this might not be the preferred behavior.
 
So one option to prevent anonymous users from accessing these pages is to set permissions accordingly. We can enable/disable anonymous access for individual lists. Here the advantage is we can let certain lists accessible by anonymous users, but on the other hand configuration needs to be done in each list individually.
 
Another option to restrict access to list views is to use out of the box feature called ViewFormsPagesLockdown Feature. View Forms Pages Lockdown Feature is a hidden feature, which if activated removes the View Application Pages permission, and the Use Remote Interfaces permission. The View Application Pages permission is the one that allows anonymous users to access Forms pages. So after activating this feature, when anonymous users try to access form pages by directly typing the URL, they will get Unauthorized Access message.
 
ViewFormPagesLockDown Feature:
 
 
In order to activate “ViewFormPagesLockDown” feature,
 
Enable-SPFeature -Identity 7c637b23-06c4-472d-9a9a-7c175762c5c4 -Url <site URL>
 
Note: If anonymous access was enabled before activating this feature, we need to disable and enable anonymous access again after this feature activation. Anonymous access settings can be changed form _layouts/setanon.aspx page.

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.