How to Get all the Time Zones used in a Server Farm using CSOM in SharePoint 2013 Online
In this blog you will see how to get all the time zones used in a server farm using CSOM in SharePoint 2013 Online
Code Snippet:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Security;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.SharePoint.Client;
-
- namespace CSOMOffice365
- {
- class Program
- {
- static void Main(string[] args)
- {
-
- string userName = "[email protected]";
-
- Console.WriteLine("Enter your password.");
- SecureString password = GetPassword();
-
-
-
-
- using (var clientContext = new ClientContext("https://c986.sharepoint.com"))
- {
-
- clientContext.Credentials = new SharePointOnlineCredentials(userName, password);
-
-
- Web web = clientContext.Web;
-
-
-
- RegionalSettings regSet = web.RegionalSettings;
- TimeZoneCollection timeZoneColl = regSet.TimeZones;
- clientContext.Load(timeZoneColl);
-
-
- clientContext.ExecuteQuery();
-
-
- foreach (Microsoft.SharePoint.Client.TimeZone timeZone in timeZoneColl)
- {
- Console.WriteLine("ID: " + timeZone.Id + " ------ TimeZone: " + timeZone.Description);
- }
- Console.ReadLine();
- }
- }
-
- private static SecureString GetPassword()
- {
- ConsoleKeyInfo info;
-
-
- SecureString securePassword = new SecureString();
- do
- {
- info = Console.ReadKey(true);
- if (info.Key != ConsoleKey.Enter)
- {
- securePassword.AppendChar(info.KeyChar);
- }
- }
- while (info.Key != ConsoleKey.Enter);
- return securePassword;
- }
- }
- }
Output: