tmsobrien

I am trying to get a collection of all the listitems in a Calendar. I want to be able to loop through all the items or events for a given day so I can compare them for a search result if a given event is missing.

I have not found any good examples. I figured it work just like a SPList and I could do something like:

SPWeb web = SPContext.Current.Web;

SPCalendarBase cal = web.GetList("myurl");

SPCalendarItemCollection calitems = cal.items;

However this does not work. Can anyone offer some help on how to get an instance of the SPCalendarBase object

Thanks Much



Re: SharePoint - Development and Programming SPCalendarItemCollection how to get an instance of

Curtis Ruppe (MicroStaff IT)

The SPCalendarItemCollection class is primarily used to populate an SPCalendarView webpart. Instead, iterate through your SPListItem objects:

Code Snippet

SPWeb spwCurrent = SPContext.Current.Web;

SPList splCalendar = spwCurrent.List["myurl"];

foreach(SPListItem li in splCalendar.Items)

{

DateTime dtStartTime = Convert.ToDateTime(li["EventDate"]);

DateTime dtEndTime = Convert.ToDateTime(li["EndDate"]);

// More code for retrieving appropriate calendar information.

}

If you feel really lucky, you can certainly use the splCalendar.GetItems(SPQuery) call using an SPQuery that defines your specific day lookup.





Re: SharePoint - Development and Programming SPCalendarItemCollection how to get an instance of

Iko Knyp

You wrote: The SPCalendarItemCollection class is primarily used to populate an SPCalendarView webpart...

Hah, that's what I am trying to do...populating the view from data accumulated from somewhere else... Which property in the SPCalendarView will take the SPCalendarItemCollection Thx






Re: SharePoint - Development and Programming SPCalendarItemCollection how to get an instance of

Iko Knyp

Found it: You use the SPCalendarItemCollection as a DataSource for the SPCalendarView control. Never mind.