RecurrenceRuleTryParse Method (String, RecurrenceRule) |
Namespace: Kettic.AspNet.Controls
using System; using Kettic.AspNet.Controls; namespace RecurrenceExamples { class ParsingExample { static void Main() { // Creates a sample appointment that starts at 6/1/2007 3:30 PM (local time) and lasts half an hour. Appointment recurringAppointment = new Appointment("1", Convert.ToDateTime("6/1/2007 3:30 PM"), Convert.ToDateTime("6/1/2007 4:00 PM"), "Sample appointment"); // Creates a recurrence range, that specifies a limit of 10 occurrences for the appointment. RecurrenceRange range = new RecurrenceRange(); range.Start = recurringAppointment.Start; range.EventDuration = recurringAppointment.End - recurringAppointment.Start; range.MaxOccurrences = 10; // Creates a recurrence rule to repeat the appointment every 2 hours. HourlyRecurrenceRule rrule = new HourlyRecurrenceRule(2, range); // 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); } } } /* This example produces the following results: Recurrence rule: DTSTART:20070601T123000Z DTEND:20070601T130000Z RRULE:FREQ=HOURLY;COUNT=10;INTERVAL=2; After parsing (should be the same): DTSTART:20070601T123000Z DTEND:20070601T130000Z RRULE:FREQ=HOURLY;COUNT=10;INTERVAL=2;*/