Posts Tagged ‘SharePoint 2010’

Multilanguage in Navigation using Webtemplate does not work

May 15, 2012

I created a webtemplate (http://msdn.microsoft.com/en-us/library/ms434313.aspx) in SharePoint and added following localized Navigation Bar to the top the navigation in the onet.xml:

<NavBar Name="$Resources:osrvcore,SspAdministrationTopNavBarTitle;" ID="1002">
<NavBarLink Name="$Resources:osrvcore,HelpText;" Url="default.aspx" />
 </NavBar>

then I created a web site based on the template and turned the multilanguage on.

The problem is that the navigation bar stays always in one language and is never localised to current language of the website. If I use the same xml file in the sitetemplate everything works correctly.

The problem is recognized as designed by Microsoft and there is only workaround available.

Solution

  1. Delete the navigation from the onet.xml
  2. Recreate the Navigation with code.

Creating the navigation programmatically

  • Create the xml file called navigation.xml with the navigation and let it be deployed to the layouts folder. The file should have following structure:
</div>
<?xml version="1.0" encoding="utf-8" ?>
<NavBars>
<NavBar Template="templatename">
<NavBarLink Url="$Resources:cmscore,List_Pages_UrlName;/page1.aspx" Name="$Resources:osrvcore,HelpText"/>
 <NavBarLink Url="$Resources:cmscore,List_Pages_UrlName;/page2.aspx" Name="$Resources:osrvcore,HelpText"/>
</NavBar>
</NavBars>
  • Load the xml file:
public IList<NavigationNode> GetNavigation(string templateName)
{
{
var fileName = SPUtility.GetGenericSetupPath("TEMPLATE\\LAYOUTS\\navigation.xml");
var navigation = new List<NavigationNode>();
var data = new XmlDocument();
data.Load(fileName);
var xpath = string.Format("/NavBars/NavBar[@Template='{0}']/NavBarLink", templateName);
var nodes = data.SelectNodes(xpath);

foreach (XmlNode node in nodes)
{
navigation.Add(new NavigationNode
{
Name = node.Attributes["Name"].Value,
Url = node.Attributes["Url"].Value
});
}

return navigation;
}
}
  • Add the navigation nodes to the top navigation. There is also handling if the url contains resources that have to be replaced
foreach (var navigationNode in GetNavigation(templatename))
{
var parsedUrl =  ParseNavigationUrl(navigationNode.Url, web.Language);
var spNavigationNode = new SPNavigationNode(navigationNode.Name, parsedUrl, true);
web.Navigation.TopNavigationBar.AddAsLast(spNavigationNode);
}
private static string ParseNavigationUrl(string url, uint language)
{
var resourceExpression = GetResourceExpressionFromString(url);
if (string.IsNullOrEmpty(resourceExpression))
return url;
var localizedString = SPUtility.GetLocalizedString(resourceExpression, string.Empty, language);           return url.Replace(resourceExpression, localizedString);
}
private static string GetResourceExpressionFromString(string text)
{
if (string.IsNullOrEmpty(text))
return string.Empty;
var dollarIndex = text.IndexOf("$");
var semicolonIndex = text.IndexOf(";");
if ((dollarIndex == -1) || (semicolonIndex == -1))
return string.Empty;
return text.Substring(dollarIndex, semicolonIndex - dollarIndex + 1);
}

Google Id/Windows Authentication in SharePoint 2010 using Windows Azure

December 11, 2011

In this article I will describe how to enable signing in using Google Id, Windows Open Id, Facebook or Yahoo account to a SharePoint 2010 site collection. As authentication provider I will use Windows Azure Platform.
Here are the steps you have to do:

Configure the Azure platform

  1. Create an account on Windows Azure Platform using your Windows Live Id. There is 90 days evaluation period available on Windows Azure that is free, additionaly the Access Control Services I will use as authnetication provider are free at least until December 2012. During the registration process you will be however asked to fill in you credit card number. For more information about pricing see this.
  2. After you created your azure account go to the Windows Azure management portal  https://windows.azure.com/.
  3. In the portal click “Services Bus, Access Control & Caching ” and then “Access Control”. See following picture
  4. Click new to create a new namespace and select a unique name for the namespace and the region where your server exists and click “Create namespace” button
  5. Wait until the namespace is activated. It takes several minutes
  6. Click the newly created namespace and then “Access Control Service”
  7. Click “Identity providers” and add the providers that should be used in your SharePoint site collection for the authentication. See folllowing image.
  8. Click Relying party application button in the left tab and add a new Relying application and fill the form as marked in the following image. The url should be the url of your sharepoint web application.
  9. Also check the “Create new rule group”
  10. Now click the “Rule groups” and click Generate. The form should look like this afterwards:
  11. Click save.
  12. Click  “Application Integration” under “Development” tab. Then “Login pages” and then your relying service application.
  13. Copy the content of the textbox und option 1. It should look like this https://yournamespace.accesscontrol.windows.net:443/v2/wsfederation?wa=wsignin1.0&wtrealm=http%3a%2f%2fsharepoint2010%2f
  14. For now you are done with the azure platform configuration. Now go to your SharePoint server where should be the claims authentication enabled.

Create and export new certificate

  1. Run following command “MakeCert.exe -r -pe -n “CN=<yournamespace>.accesscontrol.windows.net” -sky exchange -ss my”. The Makecert.exe can you find in this folder: C:\Program Files\Microsoft Office Servers\14.0\Tools
  2. Here http://msdn.microsoft.com/en-us/library/gg185932.aspx  you can find a description how to export the newly created certificate for the communication betwen SharePoint and Azure.
  3. Once you have the file go back to Azure platform to your namespace and click “Certificates and keys” and click “Add” button in the “Token signing” section.
  4. Upload the exported certificate and leave the other setings to default

Configure SharePoint to use claims
Run following script. Replace following things:

  1. Path to the certificate
  2. Password of the certificate
  3. $realm (it is the Url you gave in the Relying Application Settings as Realm). Mind the slashes.
  4. $signinurl It is the url from step 17
  5. The names of the providers.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"

$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("yourcertificatename.pfx","yourpassword")

$map1 = New-SPClaimTypeMapping "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress" -IncomingClaimTypeDisplayName "Email" -SameAsIncoming

$realm = "http://sharepoint2010/"

$signinurl = "https://yournamespace.accesscontrol.windows.net:443/v2/wsfederation?wa=wsignin1.0&wtrealm=http%3a%2f%2fsharepoint2010%2f"

New-SPTrustedIdentityTokenIssuer -Name "Azure ACS" -Description "Windows Azure ACS v2" -Realm $realm -ImportTrustCertificate $cert -ClaimsMappings $map1 -SignInUrl $signinurl -IdentifierClaim $map1.InputClaimType

New-SPTrustedRootAuthority -Name "Azure Test Token Signing" -Certificate $cert

$issuer = Get-SPTrustedIdentityTokenIssuer
$authority = Get-SPTrustedRootAuthority
$issuer.ProviderUri = $signinurl
$issuer.Update

Check if the things work:

  1. Open central administration and open Web application
  2. Click Create new Web application
  3. Switch to claims authentication
  4. Check the “Azure ACS”
  5. Create new web application
  6. Create new site collection
  7. Set the permissions on the site collection that the users have access to the site collection
  8. Log in with your Google Id to the site collection

References:  Travis Nielsen blog

Creating Secure Store Service Application through Powershell

November 24, 2011

SSSA is a good way how to store credentials for accessing external systems.
Here is a script that will help you to create such a service application through powershell.
Thanks to the codeplex project autospinstaller for the inspiration.

Add-PsSnapin Microsoft.SharePoint.PowerShell
$serviceApplicationPool  = "SecurityTokenServiceApplicationPool" #name of the application pool under which the application should run
$secureStoreDatabaseName  = "SecureStoreServiceDatabase" #the sharepoint database where the service app will store the data
$secureStoreApplicationName  ="Secure Store Service Application" #name of the service application
$secureStoreApplicationProxyName  ="Secure Store Service Application Proxy" #name of the service application proxy
$secureStoreAdministrator = "domain\administrator" #the administrator of the application
$secureStoreUser = "domain\user" #the group or user that will have access to service application. I use the group configuration
$secureStoreAdministratorEmail = "adminemail" #email of the administrator
$serviceContext = "http://localhost" # the url for getting the service application context
$targeApplicationUserName= "administrator" #user name which will be used to access the external application
$targetApplicationUserPassword = "password"
#password which will be used to access the external application
$passPhrase = "PassPhrase" #passphrase for securing the application

If ($secureStoreApplicationName -eq $null) {$secureStoreApplicationName = "State Service Application"}
# Get the service instance
$SecureStoreServiceInstances = Get-SPServiceInstance | ? {$_.GetType().Equals([Microsoft.Office.SecureStoreService.Server.SecureStoreServiceInstance])}
$SecureStoreServiceInstance = $SecureStoreServiceInstances | ? {$_.Server.Address -eq $env:COMPUTERNAME}
If (-not $?) { Throw " - Failed to find Secure Store service instance" }
# Start Service instance
If ($SecureStoreServiceInstance.Status -eq "Disabled")
{
	Write-Host  " - Starting Secure Store Service Instance..."
	$SecureStoreServiceInstance.Provision()
	If (-not $?) { Throw " - Failed to start Secure Store service instance" }
	# Wait
	Write-Host  " - Waiting for Secure Store service..." -NoNewline
	While ($SecureStoreServiceInstance.Status -ne "Online")
	{
	   Write-Host  "." -NoNewline
		Start-Sleep 1
		$SecureStoreServiceInstances = Get-SPServiceInstance | ? {$_.GetType().ToString() -eq "Microsoft.Office.SecureStoreService.Server.SecureStoreServiceInstance"}
		$SecureStoreServiceInstance = $SecureStoreServiceInstances | ? {$_.Server.Address -eq $env:COMPUTERNAME}
	}
	Write-Host  $($SecureStoreServiceInstance.Status)
}
			# Create Service Application
			$GetSPSecureStoreServiceApplication = Get-SPServiceApplication | ? {$_.GetType().Equals([Microsoft.Office.SecureStoreService.Server.SecureStoreServiceApplication])}
			If ($GetSPSecureStoreServiceApplication -eq $Null)
			{
				Write-Host  " - Creating Secure Store Service Application..."
				New-SPSecureStoreServiceApplication -Name $secureStoreApplicationName -PartitionMode:$false -Sharing:$false -DatabaseName $secureStoreDatabaseName -ApplicationPool $serviceApplicationPool -AuditingEnabled:$true -AuditLogMaxSize 30 | Out-Null
				Write-Host  " - Creating Secure Store Service Application Proxy..."
				Get-SPServiceApplication | ? {$_.GetType().Equals([Microsoft.Office.SecureStoreService.Server.SecureStoreServiceApplication])} | New-SPSecureStoreServiceApplicationProxy -Name $secureStoreApplicationProxyName -DefaultProxyGroup | Out-Null
				Write-Host  " - Done creating Secure Store Service Application."
			}
			Else {Write-Host  " - Secure Store Service Application already provisioned."}

			$secureStore = Get-SPServiceApplicationProxy | Where {$_.GetType().Equals([Microsoft.Office.SecureStoreService.Server.SecureStoreServiceApplicationProxy])}
			Start-Sleep 5
			Write-Host  " - Creating the Master Key..."
			Update-SPSecureStoreMasterKey -ServiceApplicationProxy $secureStore.Id -Passphrase $passPhrase
			Start-Sleep 5
			Write-Host  " - Creating the Application Key..."
			Update-SPSecureStoreApplicationServerKey -ServiceApplicationProxy $secureStore.Id -Passphrase $passPhrase -ErrorAction SilentlyContinue

$usernameField = New-SPSecureStoreApplicationField –Name “UserName” -Type UserName –Masked:$false
$passwordField = New-SPSecureStoreApplicationField –Name “Password” –Type Password –Masked:$true
$fields = $usernameField,$passwordField

$adminClaim = New-SPClaimsPrincipal –Identity $secureStoreAdministrator –IdentityType  WindowsSamAccountName
$userClaim = New-SPClaimsPrincipal –Identity $secureStoreUser –IdentityType  WindowsSamAccountName
$targetApp = new-spsecurestoretargetapplication -name "externalApplication" -friendlyname "externalApplication" -contactemail $secureStoreAdministratorEmail -applicationtype Group -timeoutinminutes 3
$ssApp = New-SPSecureStoreApplication –ServiceContext $serviceContext –TargetApplication $targetApp –Field$fields –Administrator $adminClaim -CredentialsOwnerGroup $userClaim
$firstCredential = ConvertTo-SecureString $targeApplicationUserName –AsPlainText –Force
$secondCredential = ConvertTo-SecureString $targeApplicationUserPassword –AsPlainText –Force
$credentialValues = $firstCredential,$secondCredential
Update-SPSecureStoreGroupCredentialMapping  –Identity $ssApp –Values $credentialValues

Start content type synchronisation from within a feature

November 7, 2011

The standard way to consume the content types from content type hub in your site collection. It is described for example here.  If you want  the content types available direct during creating of the site collection, this will not work for you. You try to start the Timer Job programmatically, but you will receive access denied exception. Because starting timer jobs is not allowed during feature activation. Here is a sample how you can consume content types immediately only for a specific site collection without permissions problems. However it includes a little bit of reflection.

using System;
using Microsoft.SharePoint;
using System.Reflection;

namespace NameSpace
{
public class ContentTypeSubscriber
{
public void Execute(SPSite site)
{
var taxonomyAssembly = Assembly.Load("Microsoft.SharePoint.Taxonomy, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c");
var subscriberType = taxonomyAssembly.GetType("Microsoft.SharePoint.Taxonomy.ContentTypeSync.Internal.Subscriber");

var processSiteMethodInfo = subscriberType.GetMethod("ProcessSite",
BindingFlags.NonPublic | BindingFlags.Instance,
null,
new[] { typeof(SPSite) },
null);

var subscriberTypeConstructor = subscriberType.GetConstructor(
BindingFlags.NonPublic | BindingFlags.Instance,
null, new Type[] { }, null
);

var subscriberInstance = subscriberTypeConstructor.Invoke(new object[] { });
processSiteMethodInfo.Invoke(subscriberInstance, new Object[] { site });
}
}
}

Restoring site or list from a full farm backup

June 12, 2011

This post covers a scenario, when a user makes some irreversible changes and the only place where the undamaged data is, is the farm full backup. The scenarios can be list deletion, site deletion, permissions damage etc.
So here are the instructions:

  1. Locate the folder where your farm full backup is and open the file spbackup.xml
  2. Find the content database name in the file and in the found node  locate a line that looks like this:
    <SPParameter Key="SHAREPOINT2010:WSS_Content.dat"><![CDATA[00000055.bak]]></SPParameter>
    
  3. 00000055.bak is the name of the database backup of the content database.
  4. Go to SQL Management Studio and create a new database.
  5. Perform a restore into this database from the backup file mentioned above. You have to change the name of the ldf and mdf file and check the “overwrite the existing database” checkbox.
  6. Now open the Central administration. Click “Backup and Restore” tab and then “Recover data from an unattached content database” link.
  7. Type in the name of the currently restored database and click Next.
  8. Navigate to a list / site collection that you want to restore and click Next.
  9. On the following page type in where you want to store the exported data of the list / site collection and click Next.
  10. When the backup is created use the Import-SPWeb command to restore the data. The command should look like this:
Import-SPWeb -Path C:\temp\backup.bak -Identity http://localhost

SSD Disks and SharePoint 2010

February 8, 2011

I have recently set up a new virtualized SharePoint development machine with a SSD Disk (Model Kingston 128GB SSDNow V-Series V+ SATA2 2.5).  I measured the time it takes to load a start page of a site collection after iisreset. The virtualization software was virtual box. The tested site collection was Enterprise Wiki. Here is the configuration of the systems:
Host system

  • Windows 7 64bit
  • 8GB RAM

Virtualized Server

  • Windows 2008 Server 64bit R2
  • SharePoint 2010
  • 4GB RAM

Here are the results

System Time (seconds) 
with SSD disk 8
with standard disk 32 

Pretty impressive

Quick tips for using Powershell in SharePoint

October 12, 2010

Here are some helpful powershell commands that I am afraid that I will forget:

This powershell command will install PowerShell ISE. A Pretty tool for editing powershell scripts:

Import-Module ServerManager;Add-WindowsFeature PowerShell-ISE

This powershell command will enable SharePoint commands:

Add-PsSnapin Microsoft.SharePoint.PowerShell

This command opens a new SPSite and root SPWeb

$spsite = new-object Microsoft.SharePoint.SPSite(“http://localhost&#8221;)

$spweb = $spsite.OpenWeb()

Creating Loops in SharePoint Designer 2010 Workflows

October 7, 2010

By default SPD 2010 does not allow possible infinite loops to be added to a workflow. Here is the guide how you can do it:

  1. Open SPD 2010
  2. Add a new Workflow
  3. Add new IfElseActivity and fill in the conditions and the actions you want to loop through
  4. Save the workflow
  5. Go to Alle Files -> Workflows -> Your workflow name  folder and open  “your workflow name.xoml” file as xml.
  6. Locate the lines that look like this:

<IfElseActivity x:Name="ID411">

<IfElseBranchActivity x:Name="ID412">

<IfElseBranchActivity.Condition>

<RuleConditionReference ConditionName="__Rule_ID412" />

</IfElseBranchActivity.Condition>

And replace if with something like this:


<WhileActivity x:Name="ID411">

<WhileActivity.Condition>

<RuleConditionReference ConditionName="__Rule_ID412" />

</WhileActivity.Condition>

&nbsp;

Keep in mind that you have to remove also the ending tag of the IfElseBranchActivity.  Keep also in mind that if you have multiple activities in the IfElseActivity taht you have to encapsulate these activities into one single SequenceActivity.

Now you can Publish your workflow back to SharePoint.

One drawback of this approach is that SPD does not support designing of a whileactivity in the worklow designer so you have to change the activities direct in the xoml file or you can replace the whileactivity again with ifelseactivity, do your changes and replace it again.

You have to also modify the web.config of the web app where you want to deploy your workflow because by default is the WhileActivity disabled. Locate following line


<authorizedType Assembly="System.Workflow.Activities, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Workflow.*" TypeName="WhileActivity" Authorized="False" />

and set the “Authorized” attribute to True.

Adding a Webpart to home.aspx during Site creating in Enterprise Wiki

September 8, 2010

Consider following scenario:

Create a custom site template based on Enterprise Wiki (Publishing Site) and add a web part to the home page during site creating.

The creating of the template is not tricky and you can find the description here.  The tricky part is actually adding the web part to the homepage.

So here is how you can do it:

Delete the module that creates the home.aspx from the onet.xml. and create it manually in code behind (I used a feature receiver on a feature that is activated when the site is created. The method that adds the homepage can look like this.

public static void AddHomePageToDocumentLibrary(SPWeb web, string pageContent)
{
        var pubWeb = PublishingWeb.GetPublishingWeb(web);
        var pageLayout = pubWeb.GetAvailablePageLayouts()[0];
        PublishingPage newPage = pubWeb.GetPublishingPages().Add("home.aspx", pageLayout);
        newPage.ListItem[FieldId.PublishingPageContent] = pageContent;
        newPage.ListItem.Update();
        newPage.Update();
}

The page content should contain following div:

<div class='ms-rtestate-read ms-rte-wpbox' contentEditable='false'><div class='ms-rtestate-read d127f8fd-2a2e-4495-9e0f-d32d5ca2e5c7' id='div_d127f8fd-2a2e-4495-9e0f-d32d5ca2e5c7'></div><div style='display:none' id='vid_d127f8fd-2a2e-4495-9e0f-d32d5ca2e5c7'></div></div>

This div is by run time replaced with an actual webpart. The guid d127f8fd-2a2e-4495-9e0f-d32d5ca2e5c7 is important as it identifies the webpart that should be added to the page.

Finally we have to add the webpart to the webpart zone.


public static void AddWebPartToHomePage(System.Web.UI.WebControls.WebParts.WebPart webPart, SPWeb web, Guid webpartId)
        {
            using (SPLimitedWebPartManager mgr = web.GetLimitedWebPartManager("seiten/home.aspx", PersonalizationScope.Shared))
            {
                string storageKeyId = StorageKeyToID(webpartId);
                webPart.ID = storageKeyId;
                mgr.AddWebPart(webPart, "wpz", 0);
            }
        }

private static string StorageKeyToID(Guid storageKey)
        {
            if (!(Guid.Empty == storageKey))
            {
                return ("g_" + storageKey.ToString().Replace('-', '_'));
            }
            return string.Empty;
        }

The webpart is the webpart we want to add, web is the web that we create and the guid is the guid that identifies the webpart. In our case it is d127f8fd-2a2e-4495-9e0f-d32d5ca2e5c7. The “wpz” zone is the hidden webpart zone that SharePoint 2010 uses to store inline webparts.

I tried to create these webparts in onet.xml, but it did not work. The webparts were simply not displayed, though all attributes were filled.

References

http://donalconlon.wordpress.com/2010/05/04/sp2010-creating-a-wiki-page-using-the-om/

SharePoint Solution Installer support for SP2010

February 28, 2010

I modified the SharePoint Solution Installer and now it supports SharePoint 2010.

I added following config entry into the setup.exe.config

<add key=”SupportedSharePointVersion” value=”2007″/>
If it contains value “2007”  then the solution can be installed only to MOSS 2007 and WSS 3.0

If it contains “2010” the the solution can be installed only to SharePoint 2010 and SharePoint Foundation.

If you leave it empty then no check for specific version of SP is done and you can install it to all above versions.

You can download the modified SSI binaries and source code from here. (It is actually a zip file renamed to jpeg because of WordPress policy.)