I have created the SharePoint list and a custom view. I need to get the list items from the specific custom view instead of all items view. How to do this using c# with caml query?
I have used below code
SPUser user = site.CurrentUser;
AudienceLoader audienceLoader = AudienceLoader.GetAudienceLoader();
SPList upcomingEventsList = site.Lists["Upcoming Events"];
SPView view = upcomingEventsList.Views["Calendar"];
SPQuery upcomingEventsQuery = new SPQuery();
upcomingEventsQuery.CalendarDate = DateTime.Now;
upcomingEventsQuery.ExpandRecurrence = true;
string date = XmlConvert.ToString(DateTime.Now, XmlDateTimeSerializationMode.Local);
upcomingEventsQuery.ViewFields = "<FieldRef Name='LinkTitle'/><FieldRef Name='ID'/><FieldRef Name='Location'/><FieldRef Name='EventDate'/><FieldRef Name='EndDate'/>";
upcomingEventsQuery.Query = "<View><Query>"+view.Views+"<Where><Geq><FieldRef Name='EventDate'/><Value IncludeTimeValue='TRUE' Type='DateTime'>" + date + "</Value></Geq></Where><OrderBy><FieldRef Name='EventDate' Ascending='True'/></Now></OrderBy></Query></View>";
SPListItemCollection SPListItemCollection = upcomingEventsList.GetItems(upcomingEventsQuery);
DataTable upcomingEventsDT = SPListItemCollection.GetDataTable();
This is not getting the calendar items properly.