locked
How to get current Sharepoint site LCID in silverlight web part. RRS feed

  • Question

  • I would like to get the current Langauge Id like 1033, 1044 etc in Silverlight web part using client object model. Please let me know how to get the language id of site in silverlight application.
    Balaji
    Thursday, January 6, 2011 11:39 AM

Answers

  • Hi Balaji,

     

    Thanks for your post.

     

    I think you can’t get the LCID directly after some research. Here are my ideas, hope it’s helpful.

    1.       Here is some information about “Understanding the Multilingual User Interface (MUI)”.I suggest you to read it at first. http://msdn.microsoft.com/en-us/library/ff800886.aspx

    2.       Frederik’s code is correct in some case. When you create a site collection based on “Norwegian” language, not alter language in UI, you will get 1044. But if you alter language in UI, it always show you 1044.

    3.       There is a workaround about this issue. The UI Language of SharePoint will be changed if you select different language. So you can use the default list or create a new list’s title to get the current SharePoint site LCID. For example, I use the default “Calendar” list in SharePoint 2010. Here is some sample code: (The title of the list will change based on the language you select)

    List calList;

    public MainPage()

    {

                    InitializeComponent();

                    ClientContext ctx = ClientContext.Current;

                    calList = ctx.Web.Lists.GetByTitle("Calendar");

                    ctx.Load(calList, ls => ls.Title);

     

                    ctx.ExecuteQueryAsync(new

                                    ClientRequestSucceededEventHandler(OnRequestSucceeded), null);

    }

     

    private void OnRequestSucceeded(object sender,

                    ClientRequestSucceededEventArgs args)

    {

                    Dispatcher.BeginInvoke(BindData);

    }

     

    private void BindData()

    {

                    if (calList.Title == "Calendar")

                    {

                                    txtListTitle.Text = "It's English UI.";

                    }

                    else if (calList.Title == "日历")

                    {

                                    txtListTitle.Text = "It's Chinese UI.";

                    }             

    }

     

    • Marked as answer by KeFang Chen Thursday, January 13, 2011 6:58 AM
    Monday, January 10, 2011 10:28 AM

All replies

  • http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.web.language.aspx

     

    So, the Web object has a Language property

     

     

    private ClientContext context = null; 
      private Web web = null; 
      private delegate void UpdateUIMethod(); 
     
      private void Init() 
      { 
       context = ClientContext.Current; 
       web = context.Web; 
       context.Load(web, w => w.Title, w => w.Description, w => w.ServerRelativeUrl, w => w.Language); 
       context.ExecuteQueryAsync(OnSiteLoadSuccess, OnSiteLoadFailure); 
      } 
     
      private void OnSiteLoadSuccess(object sender, ClientRequestSucceededEventArgs e) 
      { 
       UpdateUIMethod updateUI = LoadSiteData; 
       this.Dispatcher.BeginInvoke(updateUI); 
      } 
      private void OnSiteLoadFailure(object sender, ClientRequestFailedEventArgs e) 
      { 
       MessageBox.Show("Request Failed: " + e.Message + ", Stack Trace:" + e.StackTrace); 
      } 
    private void LoadSiteData() 
      { 
       int LCID = web.Language;
      } 
    

     

     

    This should do the trick, if not let me know.

     

    PS: It is not needed to run the LoadSiteData asynchronously in this case. but whenever you are updating any UI element (label, textbox, ...) you HAVE to.

     

    Frederik

    • Proposed as answer by Steve.Curran Thursday, January 6, 2011 8:28 PM
    Thursday, January 6, 2011 1:43 PM
  • Hi Frederik,

     

       Thanks for your reply. I have changed the language in SharePoint site and debugged the silverlight web part with the above code. The current language of my site is Norwegian(1044), but it shows the language id as 1033(English). The default language of my site is 1033, but currently the site is in Norwegian language. Also ,i have checked the culture, that also showing 1033 default English language... Other than my silverlight web part, others are changed into Norwegian which done by SharePoint.

     

    Regards,

    Balaji R


    Balaji
    Friday, January 7, 2011 4:16 AM
  • You are sure your WEB is norwegian? 

    Try checking the SITECOLLECTION's language ... 

    Friday, January 7, 2011 8:33 AM
  • Yes, I am sure. I have installed norwegian language pack.
    Balaji
    Friday, January 7, 2011 10:52 AM
  • Hi Balaji,

     

    Thanks for your post.

     

    I think you can’t get the LCID directly after some research. Here are my ideas, hope it’s helpful.

    1.       Here is some information about “Understanding the Multilingual User Interface (MUI)”.I suggest you to read it at first. http://msdn.microsoft.com/en-us/library/ff800886.aspx

    2.       Frederik’s code is correct in some case. When you create a site collection based on “Norwegian” language, not alter language in UI, you will get 1044. But if you alter language in UI, it always show you 1044.

    3.       There is a workaround about this issue. The UI Language of SharePoint will be changed if you select different language. So you can use the default list or create a new list’s title to get the current SharePoint site LCID. For example, I use the default “Calendar” list in SharePoint 2010. Here is some sample code: (The title of the list will change based on the language you select)

    List calList;

    public MainPage()

    {

                    InitializeComponent();

                    ClientContext ctx = ClientContext.Current;

                    calList = ctx.Web.Lists.GetByTitle("Calendar");

                    ctx.Load(calList, ls => ls.Title);

     

                    ctx.ExecuteQueryAsync(new

                                    ClientRequestSucceededEventHandler(OnRequestSucceeded), null);

    }

     

    private void OnRequestSucceeded(object sender,

                    ClientRequestSucceededEventArgs args)

    {

                    Dispatcher.BeginInvoke(BindData);

    }

     

    private void BindData()

    {

                    if (calList.Title == "Calendar")

                    {

                                    txtListTitle.Text = "It's English UI.";

                    }

                    else if (calList.Title == "日历")

                    {

                                    txtListTitle.Text = "It's Chinese UI.";

                    }             

    }

     

    • Marked as answer by KeFang Chen Thursday, January 13, 2011 6:58 AM
    Monday, January 10, 2011 10:28 AM
  • There is a better solution.

    You can read out the current LCID by   

     

     

    HtmlPage.Document.Cookies

    Tuesday, November 29, 2011 8:45 AM