Whenever we create a variation Hierarchy SharePoint creates an internal list as “Relationships List” which keeps the mapping of the page in different variation labels. In a scenario I have to switch between different variations on a drop down select.
When a user changes the language from the drop –down the page in the corresponding language should be displayed.
protected void OnddlLanguageSelectedIndexChanged(object sender, EventArgs e)
{
string RelativeQuery = this.Page.Request.Url.Query;
string RelativeURL = this.Page.Request.Url.AbsolutePath;
SPList objList = SPContext.Current.Site.RootWeb.Lists["Relationships List"];
SPQuery objSPQuery = new SPQuery();
objSPQuery.Query = "" + RelativeURL + "";
SPListItemCollection objItems = objList.GetItems(objSPQuery);
if (objItems != null && objItems.Count > 0)
{
objSPQuery = new SPQuery();
objSPQuery.Query = "" + Convert.ToString(objItems[0]["GroupGuid"]) + "";
objItems = objList.GetItems(objSPQuery);
if (objItems != null && objItems.Count > 0)
{
foreach (SPListItem objItem in objItems)
{
SPFieldUrl objUrl = (SPFieldUrl)(objItem.Fields["ObjectID"]);
objUrlValue = (SPFieldUrlValue)objUrl.GetFieldValue(Convert.ToString(objItem["ObjectID"]));
RedirectURL = objUrlValue.Url;
RedirectURL = RedirectURL + RelativeQuery;
if (RedirectURL.Contains(ddlLanguage.SelectedValue))
{
isPageFound = true;
this.Page.Response.Redirect(RedirectURL, false);
}
}
}
}
}
No comments:
Post a Comment