We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

MapiCalendar RecurrencePattern

I’m looking at the MapiCalendar to create recurring appointments in a calendar for a PST file. I’ve looked at the following:

string rule = “DTSTART;VALUE=DATE:20150630\r\nDTEND;VALUE=DATE:20150701\r\nRRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=TU;”;
RecurrencePattern pattern = new RecurrencePattern(rule);
DateCollection dates = pattern.GenerateOccurrences();

foreach (var date in dates) {
Console.WriteLine(date);
}

I get the following error:
The string of a recurrent rule does not correspond to the standard: 'the character ‘=’ in an option of a rule is not retrieved

Is this not in the correct format?

Also, do you have a section on your site or demos for MapiCalendar recurring appointments.

Thanks

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 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”;<o:p></o:p>

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);

}

Going back to my original post, the reason I was getting the error is because I had the following at the end of my Rule ";"

Is it possible to create a MapiCalendar event from just the following:
RecurranceRule: "DTSTART;VALUE=DATE:20150630\r\nDTEND;VALUE=DATE:20150701\r\nRRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=TU;"



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);<o:p></o:p>

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:


MapiCalendarEventRecurrence e = new MapiCalendarEventRecurrence();
e.RecurrencePattern = rec;
cal.Recurrence = e;

Hi Ashley,


This also seems to be a correct method and can be used, however our product team has also resolved EMAILNET-34940 and will be available in our next release Aspose.Email for .NET 5.7.0.

If I have the following for example:

"DTSTART;TZID=GMT Standard Time:20150912T140000\r\nDTEND;TZID=Europe/London:20150912T143000\r\nRRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=2SA"

is there a clean way to determine which class to use:
MapiCalendarWeeklyRecurrencePattern
MapiCalendarDailyRecurrencePattern
MapiCalendarMonthlyNthRecurrencePattern
MapiCalendarMonthlyRecurrencePattern

At present I am using
Aspose.iCalendar.RecurrencePattern pattern = new Aspose.iCalendar.RecurrencePattern(recurranceRule);
foreach (var rule in pattern.RRules) {
switch (rule.Frequency) {
logic to determine which class to use
}

Do you think this is a good approach, I need to be able to create recurring appointments based on a string recurrence rule, at present I am having trouble handling MapiCalendarMonthlyNthRecurrencePattern

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()<o:p></o:p>

{

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);

}

}



Going back to the following sample on your site regarding this snippet:
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,


I have tested the RRULE string using the GetOccurenceCount() and got exception while using Aspose.Email for .NET 5.6.0. Could you please test this RRULE again with the latest Aspose.Email version and let us know the feedback. Also please share the third party tool which is used to test this RRULE and return count as 2. Provide us the steps to use that tool to test this RRULE. It will help us to observe the issue and log it if required.

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,


I have tried the following code and observed that Aspose.Email returns count as 3 although it should return 2 as per the sample RRULE string. You have mentioned that you get count 0 while using Aspose.Email. Could you please test it again and let us know the feedback? We will log this issue once we get your feedback.

I have attached the sample code and output image for your reference.

Hi,


I’ve tried the code attached and get the following output? I still get 0 count.

Screenshot


Not sure I am missing anything else, I’m referencing the latest version?

Thanks

Hi Ashley,


I have tested the scenario again using Aspose.Email for .NET 5.6.0 and observed the same issue that Aspose.Email creates 3 occurrences. I have logged it as EMAILNET-34974 in our issue tracking system for further investigation by the product team. I shall write here as soon as some feedback is received in this regard.

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,


The issue EMAILNET-34940 was logged due to the NullReferenceException which was raising at cal.Recurrence.RecurrencePattern = rec. This issue is resolved and can be tested using Aspose.Email for .NET 5.7.0.

The other issue EMAILNET-34974 is logged for generation of wrong number of dates by Aspose.iCalendar.RecurrencePattern.GenerateOccurrences(). This issue is planned to be resolved in our next release Aspose.Email for .NET 5.8.0 and you will be notified automatically about the resolution.

Hope this clarifies the issue and please feel free to write us back if you have any other query in this regard.

I can’t seem to find any documentation on SlidingFlag property that you have set to false, what does this property do?