2

We are trying to set Regional Settings for new subsite in WebProvisioned event. Scenario is, we have two Variations site created, one for English and second for Arabic. We need to set Regional settings for Arabic site same as English site.

Problem that we are facing rite now is that when a site is created in English, its regional settings are "en-US", and when its variation site is created in Arabic (with timerjob execution), its regional settings remain Arabic (ar-SA) based(caldender is Hijri etc.).

We are using Event Receiver with WebProvisioned event, while debugging we found that, Regional settings for site created in Arabic are "en-US" (before we apply changes for regional settings forcefully). But when execution is finished, its regional settings are changed to "ar-SA". So its become useless to set regional settings in WebProvisioned event.

Below is the code we are using:

            web.AllowUnsafeUpdates = true;
            var ci = new System.Globalization.CultureInfo("en-US");
            var rs = new SPRegionalSettings(web, true);
            rs.LocaleId = (uint)ci.LCID;
            rs.Time24 = rs.GetDefaultTime24((uint)ci.LCID);
            rs.CalendarType = (short)rs.GetDefaultCalendarType(ci.LCID);
            rs.Collation = (short)rs.GetDefaultCollation(ci.LCID);
            web.RegionalSettings = rs;
            web.Update();
            web.AllowUnsafeUpdates = false;

If site is directly created in Arabic subsite, its regional settings are perfect. But when created with timerjob, this code executes succefully, but regional settings are default of Arabic.

What should we do?

  • Just a note: if your code comes from an event receiver - there is no need to use AllowUnsafeUpdates as there is no HttpContext involved. – Paul Strupeikis Feb 15 '16 at 10:18
0

If the site is created from the timer job, the code than creates it is executed in the regional settings of the OS/SP initial installation. Also, your WebProvisioned event may be asynchronous, so some chanes may be overriden later.
Here are two steps I'd take:

  1. Call the following code at the very beginning of both your job and your ER:
    var ci = new System.Globalization.CultureInfo("en-US"); SPUtility.SetThreadCulture(ci , ci);
  2. Ensure your WebProvisioned ER is synchronous.
  • TimerJob is default variation sites and lists job, so we can't update that. Only event receiver is custom, and YES it is synchronous. the only new line you have mentioned is SPUtility.SetThreadCulture(ci , ci);, what does this do? – Ovais Khatri Feb 15 '16 at 8:54
  • It forces the thread the code runs in to switch its default Culture settings to the one specified. Sometimes SharePoint relies on the thread's culture to set Web regional settings. – Evariste Feb 15 '16 at 8:59
  • I tried this, but not working. – Ovais Khatri Feb 15 '16 at 9:15
  • Problem is, if there is any page created in English site with some date field in pagelayout, after page is propogated, due to its calendar in hijri, its not able to convert that, and also we want user to select Grogerian date, instead of hijri. – Ovais Khatri Feb 15 '16 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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