Converting Times (UTC to Local) – SharePoint

Recently came across a scenario using SharePoint 2010, Duet, and SAP. The scenario being when submitting data to SAP from SharePoint any Date/Time fields would be stored in SAP using the local time of the user whom submitted the data. However when the data is sent back to SharePoint, the Netweaver layer converts any Date/Time fields to UTC time.

After a little research found some very useful information on MSDN that handles the conversion of UTC time to local time based on the regional settings of the SPWeb.

Two useful methods included in the SPTimeZone class:

Examples of how to implement the methods are available on MSDN

SPTimeZone Class: http://msdn.microsoft.com/en-us/library/ms464064

Programmatically creating Outlook appointments

Outlook Reference

Found myself needing to learn the basic of using the Microsoft Office API to programmatically creating appointments in Outlook. ┬áThe event will be initiated from SharePoint 2010, for various reasons I was unable to use the standard Outlook – SharePoint integration.

In this example I’ll demonstrate the basics of creating an Outlook Appointment…

First step is to add a reference into Visual Studio, Reference: Microsoft.Office.Interop.Outlook.

Once the reference is added you need to create a new Outlook Application, and then instantiate the object type you require, in this example…an Outlook appointment item.

Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();

Microsoft.Office.Interop.Outlook.AppointmentItem appointmentItem =(Microsoft.Office.Interop.Outlook.AppointmentItem)outlookApp.
CreateItem(Microsoft.Office.Interop.
Outlook.OlItemType.olAppointmentItem);

As you’ve added the reference you get all the goodness of the intelliSense, obviously makes everything a lot easier.

Specify the Start and End date / time

appointmentItem.Start = DateTime.Now;
appointmentItem.End = DateTime.Now.AddHours(1);

Reminder settings

appointmentItem.ReminderSet = true;
appointmentItem.ReminderMinutesBeforeStart = 60;

Subject, location, and saving

appointmentItem.Subject = "Be Somewhere";
appointmentItem.Location = "Location 1";
appointmentItem.Body = "blah blah blah";
appointmentItem.Save();

Instead of calling ‘Save’ the appointment can be forwarded as a VCal attachment

protected void sendAsVcal(Microsoft.Office.Interop.Outlook.AppointmentItem appointmentItem)
{
Microsoft.Office.Interop.Outlook.MailItem mailItem = appointmentItem.ForwardAsVcal();
mailItem.SenderEmailAddress = "sysadmin@corp.net"
mailItem.To = "me@me.com";
mailItem.Send();
}

I initially built this as a console app to test the functionality, but can easily be moved to a standard web application project. Code above tested on Outlook 2007 / 2010.