I’m looking at the MapiCalendar to create recurring appointments in a calendar for a PST file. I’ve looked at the following:
Hi Ashley,
Thank you for writing to Aspose Support team.
The statement seems to be missing the count of occurrence as experimented with MS Outlook. The following statement works and doesn’t raise any exception. Moreover, we have a complete documentation section, Working with Recurrences, that provides multiple examples of working with MapiCalendar items for recurrences. Please have a look at it and let us know if we could be of further help to you.
Code:
string rule = “DTSTART;VALUE=DATE:20150630\nDTEND;VALUE=DATE:20150701\nRRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=TU;COUNT=1”;
Aspose.iCalendar.RecurrencePattern pattern = new Aspose.iCalendar.RecurrencePattern(rule);
DateCollection dates = pattern.GenerateOccurrences();
foreach (var date in dates)
{
Console.WriteLine(date);
}
Thanks for the reply, I have tried your sample and nothing gets outputted.
This is the rule created in outlook: [link](http://screencast.com/t/JwcIQuWlOXlO)
it has no end date set. So wouldn’t have a count?
Thanks
Hi Ashley,
Please use the overloaded method of GenerateOccurences method that takes the start and end date as input. Please try it with the latest version of Aspose.Email API and share your feedback with us.
In addition, you can also change the End date to another month to experiment with the generated dates.
Code:
string rule = "DTSTART;VALUE=DATE:20150630\nDTEND;VALUE=DATE:20150701\nRRULE:FREQ=WEEKLY;BYDAY=TU";
Aspose.iCalendar.RecurrencePattern pattern = new Aspose.iCalendar.RecurrencePattern(rule);
DateCollection dates = pattern.GenerateOccurrences(pattern.StartDate, pattern.EndDate);
foreach (var date in dates)
{
Console.WriteLine(date);
}
Hi Ashley,
The MapiCalendar event for the recurrence rule could have been generated using the following sample code. But we are getting exception while generating one like this using MapiCalendar. The issue is already logged as EMAILNET-34940 in our bug tracking system. Once our product team shares some feedback about it, we shall update you here with the information.
Code:
DateTime StartDate = new DateTime(2015, 06, 30);
DateTime endByDate = new DateTime(2015, 07, 01);
MapiRecipientCollection coll = new MapiRecipientCollection();
coll.Add("abc@gmail.com","abc", MapiRecipientType.MAPI_TO);
MapiCalendar cal = new MapiCalendar("testLoc", "testSub", "testDesc", StartDate, endByDate, "organizer@gmail.com", coll);
//cal.Recurrence.RecurrencePattern = cal1.Recurrence.RecurrencePattern;
// Set the weekly recurrence
var rec = new MapiCalendarWeeklyRecurrencePattern
{
EndType = MapiCalendarRecurrenceEndType.NeverEnd,
PatternType = MapiCalendarRecurrencePatternType.Week,
Period = 1,
WeekStartDay = DayOfWeek.Sunday,
DayOfWeek = MapiCalendarDayOfWeek.Tuesday,
SlidingFlag = false,
OccurrenceCount = GetOccurrenceCount(StartDate, endByDate, "FREQ=WEEKLY;INTERVAL=1;BYDAY=TU"),
};
cal.Recurrence.RecurrencePattern = rec;
cal.Save("resaved.msg", AppointmentSaveFormat.Msg);
If I try the following, this seems to work with out throwing any exception:
Hi Ashley,
If I have the following for example:
Hi Ashley,
This method of selecting the pattern type seems to be fine. You may please use it and let us know in case of any issue.
Regarding problems in MapiCalendarMonthlyNthRecurrencePattern, please have a look at the following sample code and share the feedback. It creates recurrence where it occurs on every third Friday of February. Please note that February is decided on the basis of month of task start date.
static void ThirdFridayOfFebruary()
{
String path = "";
try
{
DateTime StartDate = new DateTime(2016, 2, 15);
DateTime DueDate = new DateTime(2016, 2, 15);
MapiTask task = new MapiTask("This task is number 04", "Sample Body", StartDate, DueDate);
task.State = MapiTaskState.NotAssigned;
// Set the yearly recurrence
var rec = new MapiCalendarMonthlyNthRecurrencePattern
{
EndType = MapiCalendarRecurrenceEndType.NeverEnd,
OccurrenceCount = 0,
PatternType = MapiCalendarRecurrencePatternType.MonthNth,
Period = 12,
WeekStartDay = DayOfWeek.Sunday,
DayPosition = Aspose.Email.Mail.Calendaring.DayPosition.Third,
DayOfWeek = MapiCalendarDayOfWeek.Friday,
};
task.Recurrence = rec;
task.Save(path + "TaskThirdFridayOfFeb.msg", TaskSaveFormat.Msg);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private static uint GetOccurrenceCount(DateTime start, DateTime endBy, string rrule) { Aspose.iCalendar.RecurrencePattern pattern = new Aspose.iCalendar.RecurrencePattern(string.Format("DTSTART:{0}\r\nRRULE:{1}", start.ToString("yyyyMMdd"), rrule)); Aspose.iCalendar.DateCollection dates = pattern.GenerateOccurrences(start, endBy); return (uint)dates.Count; }
for the following rrule I would expect the count to be 2 but returns 0
string rrule = "DTSTART:20150813\r\nRRULE:FREQ=YEARLY;BYMONTH=8;BYMONTHDAY=10;UNTIL=20170812T230000Z";
these are values I'm passing to this method
"Start:13/08/2015 00:00:00 - End:12/08/2017 23:00:00"
I've tried the above with another third party dll and it returns 2
Hi Ashley,
Hi,
I am using .NET 5.6.0, I;ve tested the rule again. Screen shot can be found [here](http://images.devs-on.net/Image/2MuojQKRapoAS7zt-Region.png)
as well as the output from DDay.ICal
Hope this helps.
Thanks
Hi,
Hi,
Hi Ashley,
The issues you have found earlier (filed as EMAILNET-34940) have been fixed in this update.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Hi,
I have tried the above with the new release and still the same output:
http://images.devs-on.net/Image/AiAi8lFJw4WZzDO8-Region.png
Thanks
Hi Ashley,
I can’t seem to find any documentation on SlidingFlag property that you have set to false, what does this property do?