Code Snippet:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Security;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Microsoft.SharePoint.Client;
  9. namespace CSOMOffice365
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. string userName = "[email protected]";
  16. Console.WriteLine("Enter your password.");
  17. SecureString password = GetPassword();
  18. // ClienContext - Get the context for the SharePoint Online Site
  19. // SharePoint site URL - https://c986.sharepoint.com
  20. using (var clientContext = new ClientContext("https://c986.sharepoint.com"))
  21. {
  22. // SharePoint Online Credentials
  23. clientContext.Credentials = new SharePointOnlineCredentials(userName, password);
  24. // Get the SharePoint web
  25. Web web = clientContext.Web;
  26. // Regional Settings: Gets the collection of time zones used in a server farm.
  27. // Reference: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.regionalsettings.timezones.aspx
  28. RegionalSettings regSet = web.RegionalSettings;
  29. TimeZoneCollection timeZoneColl = regSet.TimeZones;
  30. clientContext.Load(timeZoneColl);
  31. // Execute the query to the server
  32. clientContext.ExecuteQuery();
  33. // Gets the collection of time zones used in a server farm.
  34. foreach (Microsoft.SharePoint.Client.TimeZone timeZone in timeZoneColl)
  35. {
  36. Console.WriteLine("ID: " + timeZone.Id + " ------ TimeZone: " + timeZone.Description);
  37. }
  38. Console.ReadLine();
  39. }
  40. }
  41. private static SecureString GetPassword()
  42. {
  43. ConsoleKeyInfo info;
  44. //Get the user's password as a SecureString
  45. SecureString securePassword = new SecureString();
  46. do
  47. {
  48. info = Console.ReadKey(true);
  49. if (info.Key != ConsoleKey.Enter)
  50. {
  51. securePassword.AppendChar(info.KeyChar);
  52. }
  53. }
  54. while (info.Key != ConsoleKey.Enter);
  55. return securePassword;
  56. }
  57. }
  58. }
Output: