How to set Recurrence string in Mapi Calender

Hello Team,


Can you please provide any example of daily recurrence and can tell us how to set recurrence string ?

Please refer the screenshot.

Thank You.

Regards,
Amit

Hi Amit,


Thank you for contacting Aspose support team.

You may please use following sample code to achieve this functionality and share the feedback.

DateTime startDate = DateTime.Now.Date.AddHours(12);
MapiCalendarEventRecurrence recurrence = new MapiCalendarEventRecurrence();
MapiCalendarRecurrencePattern pattern = recurrence.RecurrencePattern = new MapiCalendarDailyRecurrencePattern();

pattern.EndDate = new DateTime(2017, 6, 3, 6, 30, 0);
pattern.EndType = MapiCalendarRecurrenceEndType.EndAfterDate;
pattern.Period = 1;
pattern.StartDate = new DateTime(2017, 5, 25, 6, 0, 0);

// Create the appointment

MapiCalendar appointment = new MapiCalendar("This is location of meeting",
    "Appointment",
    "This is a sample meeting body content",
    new DateTime(2017, 5, 25, 6, 0, 0),
    new DateTime(2017, 6, 3, 6, 30, 0)
);

appointment.Recurrence = recurrence;
appointment.Save("result.msg", Aspose.Email.Calendar.AppointmentSaveFormat.Msg);

Hi Amit,


We have further investigated your requirement and observed that in Aspose.EMail for .NET 6.4.0, appointment recurrence time is set to UTC time. As a workaround if we add the current system timezone to the recurrence time, it generates the required time in recurrence i.e. start time as 6:00 am instead of 1;00 am. You may please try this solution using Aspose.Email for .NET 6.4.0 and share the feedback. Please notice the use of following statement:

“TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now)”
MapiCalendarEventRecurrence recurrence = new MapiCalendarEventRecurrence();
MapiCalendarRecurrencePattern pattern = recurrence.RecurrencePattern = new MapiCalendarDailyRecurrencePattern();

pattern.EndDate = new DateTime(2017, 6, 3, 6, 30, 0) + TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);
pattern.EndType = MapiCalendarRecurrenceEndType.EndAfterDate;

//pattern.OccurrenceCount = 10;

pattern.Period = 1;
pattern.StartDate = new DateTime(2017, 5, 25, 6, 0, 0) + TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now);

// Create the appointment

MapiCalendar appointment = new MapiCalendar("This is location of meeting",
    "Appointment",
    "This is a sample meeting body content",
    new DateTime(2017, 5, 25, 6, 0, 0),
    new DateTime(2017, 6, 3, 6, 30, 0)
);

appointment.Recurrence = recurrence;
appointment.Save("result.msg", AppointmentSaveFormat.Msg);

Hello Team,


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.

Please see the following code :

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.

Is there any work-around that we can do to set duration explicitly ?

Please look in it.

Thank You.

Regards,
Amit

Hi Amit,


Thank you for sharing the feedback.

I have used your sample code to generate PST file and saved the output MSG as well before adding it to PST. Aspose.Email for .NET 6.4 is used for testing. I am afraid that no issue is observed and time is properly maintained in MSG file as well as in PST. I am using Outlook 2013 for testing here.

The output MSG file, PST file and comparison image is attached here for your reference. Please analyze it and share the feedback. Also please mention where and how you observed the duration as -1410 minutes as I could not observe this number anywhere.

Hello Team,


Did you tried with outlook 2007 & Outlook 2010, its not working well.

And yes when we have outlook 2013 or above it works well but if it has outlook 2007 & 2010 the duration is not calculated properly.

Can you please check with this.

Thank You.

Regards,
Amit

Hi Amit,


We have opened it in MS Oultook 2007 and could not observe any issue as you have mentioned. Please find the attached screenshot from Outlook 2007 for your kind reference. We couldn’t observe the output in MS Outlook 2010 due to unavailability at our end. Also, as requested earlier, please share with us where to observe the value -1410 in the output as we couldn’t find this value anywhere at our end.

Hello Team,


Please find the screenshot of my machine saved pst using the same code mentioned earlier.

And i’ve also attached pst file too.

I’m able to reproduce at my end.

Thank You.

Regards,
Amit

Hi Amit,


We have tested the above code samples with the latest version of the API (as well as 6.4.0) at our end and no such issues is faced with any version of MS Outlook. We strongly recommend you to use the latest version of the API as this is the version against which we can provide you with any support. If you happen to face the same issue with the latest version of the API, please share your exact code sample with us for further investigation at our end. We appreciate your understanding in this regard.