Thursday, July 22, 2010

recurrence-not-showing-on-calendar-list

http://www.sharepointdev.net/sharepoint--development-programming/recurrence-not-showing-on-calendar-list-43190.shtml

Add new item in Sharepoint Calendar Programmatically.

I used the below code to add new item in sharepoint calendar. Initially the item used to come in AllEvents view ONLY. It was not getting displayed in Calendar view. I just changed Event Type =0 and it worked....Below is the working code which will show item in calendar view too.
SPWeb site = new SPSite("http://moss-ocs:8096/doccenters/IS").OpenWeb();
SPList cal = site.Lists["Calendar"];
SPListItem calEvent = cal.Items.Add();
calEvent["Title"] = "Training19";
//string recurrence = "" +
//"su" +
//"" +
//"2010-09-20T09:00:00Z" +
//"
";
//calEvent["RecurrenceData"] = recurrence;
calEvent["EventType"] = 0;
calEvent["EventDate"] = new DateTime(2010, 7, 29, 8, 0, 0);
calEvent["EndDate"] = new DateTime(2010, 7, 30, 9, 0, 0);
calEvent["UID"] = System.Guid.NewGuid();
calEvent["TimeZone"] = 13;
calEvent["Description"] = "
";
calEvent["fAllDayEvent"] = 0;
calEvent["fRecurrence"] = 0;
calEvent.Update();
cal.Update();