Extending VariationRoot.aspx Redirection in SharePoint

Some code used to extend variation redirection logic based on a preferred locale setting in the users profile. If the property is not present or blank it falls back to default variations logic. A locale picker to set this value will be posted soon.

 
 

using System;

using Microsoft.SharePoint;

using CCE.SharePoint.UserControls;

using CCE.SharePoint.Utility;

using Microsoft.Office.Server.UserProfiles;

using Microsoft.SharePoint.Utilities;

 
 

namespace CCE.SharePoint.UserControls

{

public class VariationsRootLanding : CCEBaseUserControl

{

 
 

protected override void OnLoad(EventArgs e)

{

string targetUrl = this.GetRedirectTargetUrl();

 

if (!string.IsNullOrEmpty(targetUrl))

{

SPUtility.Redirect(targetUrl, SPRedirectFlags.Default, Context);

}

else

{

SPUtility.Redirect(“VariationRoot.aspx”, SPRedirectFlags.Default, Context);

}

}

 
 

private string GetRedirectTargetUrl()

{

String url = “”;

 
 

try

{

String loginName = SPContext.Current.Web.CurrentUser.LoginName;

 
 

UserProfile currentUserProfile = Utility.UserProfiles.GetUserProfile(loginName);

String preferredLocale = Utility.UserProfiles.GetSinglePropertyValue(currentUserProfile, “preferredLocale”);

 
 

using (SPSite _SPSite = new SPSite(SPContext.Current.Site.ID))

{

using (SPWeb rootWeb = _SPSite.RootWeb)

{

foreach (SPWeb subWeb in rootWeb.Webs)

{

if (subWeb.Locale.ToString() == preferredLocale)

{

url = “/” + subWeb.Name;

}

}

}

}

}

catch (Exception)

{

//Log error

}

 
 

return url;

}

}

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: