|
Had a requirement to staple a feature to site templates so that despite the server living in perth, east coast users would have their time-zone set correctly for the site they were creating. using Microsoft.SharePoint
namespace TimeZoneFeature
{
public class TimeZoneReceiver : SPFeatureReceiver
{
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SetTimeTimeZoneId(properties);
}
private static void SetTimeTimeZoneId(SPFeatureReceiverProperties properties)
{
using (var webSite = (SPWeb) properties.Feature.Parent)
{
if (webSite.IsRootWeb)
{
return;
}
string url = webSite.Url;
var regionalSettings = new SPRegionalSettings(webSite);
SPTimeZone timeZone = regionalSettings.TimeZone;
int tz = DeterminTimeZoneFromUrl(url);
if (tz != timeZone.ID)
{
timeZone.ID = (ushort) tz;
webSite.Update();
}
}
}
}
}
Labels |
TimeZones

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Hosted generously by CustomWare








