-
Notifications
You must be signed in to change notification settings - Fork 231
Assigning attendees and resources to events
axunonb edited this page Oct 17, 2024
·
3 revisions
Several calendar components can have attendees and resources.
Working with Attendees
Here is a short example demonstrating how to add an Attendee
to an Event
:
var now = DateTime.Now;
var later = now.AddHours(1);
var e = new CalendarEvent
{
Start = new CalDateTime(now),
End = new CalDateTime(later),
};
var attendee = new Attendee
{
CommonName = "Rian Stockbower",
Rsvp = true,
Value = new Uri("mailto:rstockbower@gmail.com")
};
e.Attendees = new List<IAttendee> {attendee};
var calendar = new Calendar();
calendar.Events.Add(e);
var serializer = new CalendarSerializer();
var icalString = serializer.SerializeToString(calendar);
Console.WriteLine(icalString);
Output:
BEGIN:VCALENDAR
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
VERSION:4.0
BEGIN:VEVENT
ATTENDEE;CN=Rian Stockbower;RSVP=TRUE:mailto:rstockbower@gmail.com
DTEND:20160829T113706
DTSTAMP:20160829T143706Z
DTSTART:20160829T103706
SEQUENCE:0
UID:5489af48-6ccb-4ad6-aa33-39db4d549c49
END:VEVENT
END:VCALENDAR
Resources are just strings; they're often used to represent projectors, rooms, and other resources. Working with strings is much simpler than working with Attendees.
var now = DateTime.Now;
var later = now.AddHours(1);
var e = new CalendarEvent
{
Start = new CalDateTime(now),
End = new CalDateTime(later),
};
e.Resources = new HashSet<string>
{
"Projector",
"Room A",
"DVD player",
"Photoshop license A"
};
var calendar = new Calendar();
calendar.Events.Add(e);
var serializer = new CalendarSerializer();
var icalString = serializer.SerializeToString(calendar);
Console.WriteLine(icalString);
Output:
BEGIN:VCALENDAR
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
VERSION:4.0
BEGIN:VEVENT
DTEND:20160829T113956
DTSTAMP:20160829T143956Z
DTSTART:20160829T103956
RESOURCES:Projector
RESOURCES:Room A
RESOURCES:DVD player
RESOURCES:Photoshop license A
SEQUENCE:0
UID:73d81fac-5540-43e1-82e1-c8354369306d
END:VEVENT
END:VCALENDAR
ical.net does not fully model the Resources property. For most use cases, its treatment is probably sufficient.