Archive for December, 2011

Setting My Regional Settings

December 16th, 2011 No comments

The quesion that came up today was if the SharePoint Server is set to a specific time zone and users are all around the world, how would I programmatically set the right time zone under “My regional settings” for those users in a batch operation?

SPUser object has a property called RegionalSettings by which you can change the regional settings per user.First you need to create an SPRegionalSettings object, set its TimeZone.Id to whatever you wish.

SPRegionalSettings spReg = new SPRegionalSettings(web, true);
spReg.TimeZone.ID = 10; //Toronto

Get the list of all available time zones from here, see the offical MSDN documentation here.

As you can see, SPRegionalSettings takes two parameters, the SPWeb and a boolean. Make sure you pass true to specify that the regional settings object you are creating pertains to the user not the web. Finally set the RegionalSettings property to the settings that you just created above.

user.RegionalSettings = spReg;

user and web variables are your SPUser and SPWeb objects which can be obtained in several ways depending on how you want to go about this. If you are looping through a lot of users to apply this change, you may want to factor in the performance impact and the time required to get this done.

Categories: MOSS 2007, SharePoint 2010 Tags: