Question

I have created following function in C# to create appointments in Outlook. Every thing is working fine but when I tried to set appoint on 8th April 2014 (dd/MM/YYYY) the appointment get set in Outlook on 4th August 2014.

I have tried casting as DateTime.ParseExact(DateTimeVal, "dd/MM/yyyy H:mm", null), but it doesn't work.

public void OutLookReminder(string DateTimeVal)
{
    Outlook.Application outlookApp = new Outlook.Application(); // creates new outlook app
    Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem); // creates a new appointment

    oAppointment.Subject = "........Subject"; // set the subject
    oAppointment.Body = "--------Body"; // set the body
    oAppointment.Location = "-------Location"; // set the location
    oAppointment.Start = DateTime.ParseExact(DateTimeVal, "dd/MM/yyyy H:mm",null); // Set the start date 
    oAppointment.End = DateTime.ParseExact(DateTimeVal, "dd/MM/yyyy H:mm", null); // End date 
    oAppointment.ReminderSet = true; // Set the reminder
    oAppointment.ReminderMinutesBeforeStart = 15; // reminder time
    oAppointment.Importance = Outlook.OlImportance.olImportanceHigh; // appointment importance
    oAppointment.BusyStatus = Outlook.OlBusyStatus.olBusy;

    // save the appointment
    oAppointment.Save();
}
Was it helpful?

Solution

Parsing Format you specify in DateTime.ParseExact(,"Formate!!!",) Is To identify The date field and Year And Month etc.... Then it is stored into datetime variable.....

I think Your Culture is "MM/dd/yyyy" try to parse in this format

Answer:

DateTime t1=DateTime.ParseExact(DateTimeVal, "MM/dd/yyyy H:mm",null);

This will give u exactly what you want...

Note that if u again parse this formated field answer will be according to you culture...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top