1

I have clock application which works fine, until user changes language to different than English. The problem lies because SPRegionalSettings.GlobalTimeZones property returns time zone collection in language which is set by user profile. Is there any other possible way to get timezone collection in English in whatever situation there is with language and regional settings?

2

SPRegionalSettings.TimeZone property gets the time zone that is used on the SharePoint server.

Example

using (var site = new SPSite(siteUrl))
{
   using (var web = site.OpenWeb())
   {
       var regionalSettings = web.RegionalSettings;
       var tz = regionalSettings.TimeZone;
       Console.WriteLine(tz.Description);
   }
}
1

Vadim Gremyachev posted almost right solution, but it is lacking, because the SPWeb object still keeps current users language settings. After some experimentations with objects and powershell, I remembered that SPSecurity.RunWithElevatedPrivileges opens web as administrator and uses default settings (language as well), so I wrapped Vadim Gremyachev code in SPSecurity.RunWithElevatedPrivileges method.

Example

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (var site = new SPSite(siteUrl))
    {
        using (var web = site.OpenWeb())
        {
           var regionalSettings = web.RegionalSettings;
           var tz = regionalSettings.TimeZone;
           Console.WriteLine(tz.Description);
        }
     }
});

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.