Click or drag to resize
RecurrenceRuleToString Method
Converts the recurrence rule to it's equivalent string representation.

Namespace: Kettic.AspNet.Controls
Assembly: Kettic.AspNet.Controls (in Kettic.AspNet.Controls.dll) Version: 2014.4.1129.0 (2014.04.1129.0)
Syntax
public override string ToString()

Return Value

Type: String
The string representation of this recurrence rule.
Remarks
The string representation is based on the iCalendar data format (RFC 2445).
Examples
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;*/
See Also