Another thing on the WSS syllabus is “Add a recurring event to a calendar”. Well, I gave it a go, and failed. It was actually pretty tough. In the end, I found myself referring to ‘How to: Add a Recurring Event to Lists on Multiple Sites‘. It’s a pretty good article, and talks about creating a Meeting Workspace and attaching it too, but the short version of it is my code…
SPList cal = site.Lists["Calendar"];
SPListItem calEvent = cal.Items.Add();
calEvent["Title"] = "Frequent Event";
string recurrence = "<recurrence><rule>" +
"<repeat><daily dayFrequency='2'/></repeat>" +
calEvent["RecurrenceData"] = recurrence;
calEvent["EventType"] = 1;
calEvent["EventDate"] = new DateTime(2009, 1, 26, 8, 0, 0);
calEvent["EndDate"] = new DateTime(2009, 1, 26, 9, 0, 0);
calEvent["UID"] = System.Guid.NewGuid();
calEvent["TimeZone"] = 13;
calEvent["Recurrence"] = -1;
One tricky bit of this would be the CAML for the recurrence; this is described fairly well in the article linked to above. Another issue would be simply knowing the correct columns to populate! Still, the code created an event that recurs every two days…
4 thoughts on “WSS Practice: Create a Calendar Event”
Can you show how to change the above recurring event to “no end date”. I am having problem with it.
Not sure – I assume you’ve tried not setting one?
Am trying to set the event date @ run time but its not working. With the hard coded vlaue as in your example it works. Is there any reason why you cannot assign the
calEvent[“EventDate”] = new DateTime(2009, 1, 26, 8, 0, 0); @ runtime
calEvent[“EventDate”] = new DateTime(nYear, nMonth, nDay, nHour,nMin ,nSec);
What leaps to mind is, are you sure that your date/time values are for a valid DateTime? No 32nd days, or 13th months?
Otherwise, no, I’ve no idea why that wouldn’t work.