I'm trying to change the Sharepoint 2010 Language using a drop down list on a web part with the values. It work's fine but only change the language in the current page, not in all site. Here's the code:
using System;
using System.Threading;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.ComponentModel;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using Microsoft.SharePoint.Utilities;
namespace Contoso.Intranet.WebTemplates.SPSITEtestwebpart
{
[ToolboxItemAttribute(false)]
public class SPSITEtestwebpart : System.Web.UI.WebControls.WebParts.WebPart
{
DropDownList ddlIdioma;
protected override void CreateChildControls()
{
ddlIdioma = new DropDownList();
ddlIdioma.AutoPostBack = true;
ddlIdioma.ID = "ddlIdioma";
ddlIdioma.Items.Add("Seleccione Idioma...");
ddlIdioma.Items.Add("Español");
ddlIdioma.Items.Add("Ingles");
ddlIdioma.DataBind();
this.Controls.Add(ddlIdioma);
ddlIdioma.SelectedIndexChanged += new EventHandler(ddlIdioma_SelectedIndexChanged);
}
protected void ddlIdioma_SelectedIndexChanged(object sender, EventArgs e)
{
Lenguaje();
}
protected void Lenguaje()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite("http://alejandroa-pc/sites/publishing"))
{
foreach (SPWeb web in site.AllWebs)
{
web.AllowUnsafeUpdates = true;
if (Page.IsPostBack)
{
if (ddlIdioma.SelectedValue.ToString() == "Español")
{
int idioma = 3082;
Thread.CurrentThread.CurrentCulture = new CultureInfo(idioma);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(idioma);
}
else if (ddlIdioma.SelectedValue.ToString() == "Ingles")
{
int idioma = 1033;
Thread.CurrentThread.CurrentCulture = new CultureInfo(idioma);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(idioma);
}
else
{
int idioma = 1033;
Thread.CurrentThread.CurrentCulture = new CultureInfo(idioma);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(idioma);
}
}
}
}
});
}
}
}