Question

I am trying to create an recurring appointment from code for telerik radschedular.

Appointment recurringAppointment = new Appointment("1",
           Convert.ToDateTime("12/12/2012 3:30 PM").ToUniversalTime(),
           Convert.ToDateTime("12/12/2012 4:00 PM").ToUniversalTime(),
           "Sample appointment");

RecurrenceRange range = new RecurrenceRange();
range.Start = recurringAppointment.Start;
range.EventDuration = recurringAppointment.End - recurringAppointment.Start;
range.MaxOccurrences = 10;
HourlyRecurrenceRule rrule = new HourlyRecurrenceRule(2, range);

After creating the appointment and the recurrence rule, I am not able to combine them. The 'RecurrenceRule' property of telerik Appointment accepts a string. So I am not able to add my HourlyRecurrenceRule to the appointment I created.

Any kind of c# code help on this will be appreciated.

Était-ce utile?

La solution

As Brian Mains points out in this article:

Repetition can be specified as hourly, daily, weekly, monthly, or yearly, and can end at a certain date or interval. You see that this rule is passed along to the Appointment as a string; the final result looks something like the following:

DTSTART:20081122T143000Z\r\nDTEND:20081122T170000Z\r\nRRULE:FREQ=WEEKLY;

UNTIL=20091021T040000Z;INTERVAL=1\r\n

In Telerik's examples you can see that the RecurrenceEditor accepts a RecurrenceRule object, but the Appointment's RecurrenceRule property only accepts the string representation of the RecurrenceRule object.

Right after your last line of code, just add this and it should do the trick:

recurringAppointment.RecurrenceRule = rrule.ToString()

Autres conseils

It looks as you got the code from their documentation:

http://www.telerik.com/help/aspnet-ajax/scheduler-working-with-recurring-appointments.html

Heres the rest of the code (from the url above)

// Prints the string representation of the recurrence rule:
string rruleAsString = rrule.ToString();
Console.WriteLine("Recurrence rule:\n\n{0}\n", rruleAsString);
// The string representation can be stored in a database, etc.
// ...
// Then it can be reconstructed using TryParse method:
RecurrenceRule parsedRule;
RecurrenceRule.TryParse(rruleAsString, out parsedRule);
Console.WriteLine("After parsing (should be the same):\n\n{0}", parsedRule);

The 2 types cannot be "combined", you save your appointment in your database with the recurrence rule string and when you load it you use the TryParse method to recreate a new recurrence rule with the same properties.

Hope it helps :)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top