I tried to do that but looks like the duration property is not getting calculated properly it comes in some -1410 minutes, when i open the saved pst.
static void Main(string[] args)
{
//This is start date of appointment
DateTime start = new DateTime(2017, 05, 25, 18, 00, 00) + TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now); // start = {5/25/2017 6:00:00 PM}(MM//DD//YYYY)
// DateTime end = new DateTime(2017, 05, 25, 18, 30, 00);
//This is end date of recurrance
DateTime end_rec = new DateTime(2017, 06, 03, 18, 30, 00) + TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now); //end_rec = {6/3/2017 6:30:00 PM}(MM//DD//YYYY)
m_ObjPersonalStorage = PersonalStorage.Create(“C:\test_.pst”, FileFormatVersion.Unicode);
FolderInfo f_FolderInfoObj = createAsposeFolder("\Calendar");
Appointment f_objAppointment = new Appointment(“Test”, “Subject”, “BOdy”, start,
end_rec, null,
null);
MailMessage f_objMsg = new MailMessage();
try
{
f_objMsg.AddAlternateView(f_objAppointment.RequestApointment());
}
catch (Exception ex){}
MapiMessage f_objMapiMsg = MapiMessage.FromMailMessage(f_objMsg);
MapiCalendar f_MapiCalendarObj = (MapiCalendar)f_objMapiMsg.ToMapiMessageItem();
#region Setting Daily Recurrance
//I am setting daily recurrance with that End By with date on Sat 6/3/2017 (MM//DD//YYYY)
MapiCalendarDailyRecurrencePattern f_mapiCalenderDailyRecPat = new MapiCalendarDailyRecurrencePattern();
f_mapiCalenderDailyRecPat.PatternType = MapiCalendarRecurrencePatternType.Day;
f_mapiCalenderDailyRecPat.EndType = MapiCalendarRecurrenceEndType.EndAfterDate;
// f_mapiCalenderDailyRecPat.EndDate = end_rec;
f_mapiCalenderDailyRecPat.Period = 1;
MapiCalendarEventRecurrence f_mapiCalevntrec = new MapiCalendarEventRecurrence();
f_mapiCalevntrec.RecurrencePattern = f_mapiCalenderDailyRecPat;
f_MapiCalendarObj.Recurrence = f_mapiCalevntrec;
#endregion
f_FolderInfoObj.AddMapiMessageItem(f_MapiCalendarObj);
//After saving the item in pst when we open in the pst don’t know why its changing the time of recurrance if you open
//the pst and open recurrance its says Start is 12:30PM (it should be 6:00:00 PM) and
//the End Time is 1:30PM (it should be 6:30:00 PM) i don’t know why its getting changed.
// Can you please tell me how to set the same time as what i’ve provided, cause its kind of invalid to me.
}
private static FolderInfo createAsposeFolder(String p_FolderPath)
{
string METHOD_NAME = “createAsposeFolder”;
String[] f_FolderNames = null;
int f_Count = 0;
FolderInfo f_ParentFolderObj = null;
FolderInfo f_FolderInfoObj = null;
String f_FolderType = String.Empty;
try
{
f_FolderType = “IPF.Appointment”;
f_ParentFolderObj = m_ObjPersonalStorage.RootFolder;
if (!String.IsNullOrEmpty(p_FolderPath))
{
//if (p_FolderPath.Contains(RootFodler))
//{
// //Replace the “IPMRoot\Top of Personal Folders\” with space
// p_FolderPath = p_FolderPath.Replace(RootFodler, “”);
//}
f_FolderNames = p_FolderPath.Split(new String[] { “\” },
StringSplitOptions.RemoveEmptyEntries);
}
f_Count = f_FolderNames.Length;
if (0 == f_Count)
{
f_FolderInfoObj = f_ParentFolderObj;
}
else
{
for (int Index = 0; Index < f_Count; Index++)
{
try
{
f_FolderInfoObj = null;
if (f_ParentFolderObj != null)
{
f_FolderInfoObj = f_ParentFolderObj.GetSubFolder((f_FolderNames[Index]));
if (f_FolderInfoObj == null)
{
string FolderName = f_FolderNames[Index].Replace("%2F", “/”).Replace("%5C", @"").Replace("%25", “%”);
f_FolderInfoObj = f_ParentFolderObj.GetSubFolder(FolderName);
if (f_FolderInfoObj == null)
{
f_FolderInfoObj = f_ParentFolderObj.AddSubFolder(FolderName, f_FolderType);
}
}
f_ParentFolderObj = f_FolderInfoObj;
}
else
{
break;
}
}
catch (Exception obEx)
{
//FolderInfoCollection f_FolderCollection = m_ObjPersonalStorage.RootFolder.GetSubFolders();
FolderInfoCollection f_FolderCollection = f_ParentFolderObj.GetSubFolders();
foreach (FolderInfo curFolder in f_FolderCollection)
{
try
{
if (curFolder.DisplayName.ToLower() == (f_FolderNames[Index]).ToLower())
{
f_ParentFolderObj = curFolder;
f_FolderInfoObj = f_ParentFolderObj;
break;
}
}
catch (Exception ex1)
{
}
}
}
}
}
}
catch (Exception ex)
{
}
return f_FolderInfoObj;
}
I’ve also attached the saved pst in the attachment.
Please look in it.
Thank You.