Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How to Get all the Time Zones used in a Server Farm using CSOM in SharePoint 2013 Online
WhatsApp
Vijai Anand Ramalingam
8y
6.2
k
0
0
25
Blog
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();
// ClienContext - Get the context for the SharePoint Online Site
// SharePoint site URL - https://c986.sharepoint.com
using
(var clientContext =
new
ClientContext(
"https://c986.sharepoint.com"
))
{
// SharePoint Online Credentials
clientContext.Credentials =
new
SharePointOnlineCredentials(userName, password);
// Get the SharePoint web
Web web = clientContext.Web;
// Regional Settings: Gets the collection of time zones used in a server farm.
// Reference: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.regionalsettings.timezones.aspx
RegionalSettings regSet = web.RegionalSettings;
TimeZoneCollection timeZoneColl = regSet.TimeZones;
clientContext.Load(timeZoneColl);
// Execute the query to the server
clientContext.ExecuteQuery();
// Gets the collection of time zones used in a server farm.
foreach
(Microsoft.SharePoint.Client.TimeZone timeZone
in
timeZoneColl)
{
Console.WriteLine(
"ID: "
+ timeZone.Id +
" ------ TimeZone: "
+ timeZone.Description);
}
Console.ReadLine();
}
}
private
static
SecureString GetPassword()
{
ConsoleKeyInfo info;
//Get the user's password as a SecureString
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:
Up Next
How To Create A Modern Document Library In SharePoint 2010/2013/Online Using CSOM
Ebook Download
View all
Getting Started with SharePoint Framework Development using TypeScript, PnP JS, and React JS
Read by 4.9k people
Download Now!
Learn
View all
Membership not found