Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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);
                            }
                        }
                    }
                }
            });
        }

    }
}
share|improve this question
add comment

1 Answer 1

The display language per user is stored in a cookie which you set like this:

<script type ="text/javascript"> 
// <![CDATA[
function OnSelectionChange(value)
{
    var today = new Date();
    var oneYear = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);
    var url = window.location.href;
    document.cookie = "lcid=" + value + ";path=/;expires=" + oneYear.toGMTString();
    window.location.href = url;
}
// ]]>
</script>

See Understanding the Multilingual User Interface (MUI)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.