1

here I tried something but that's not up to the mark
objQuery.Query = @"<Where><DateRangesOverlap><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /><FieldRef Name='RecurrenceID' /><Value Type='DateTime'><Today /></Value></DateRangesOverlap></Where><OrderBy><FieldRef Name='EventDate' Ascending='True' /></OrderBy>";
it shows result like below snippet
enter image description here
Events in Calendar List are as below Snippet

enter image description here


Here I only want to display future recurrence events ,so how can i achieve that,please help
Thanks In Advance.

2 Answers 2

1

Valid values for DateRangesOverlap are <Year>, <Month>, <Now>.

If you want to get future recurrence events for single month than use <Month>.

If you want to get future recurrence events for entire year than use <Year>.

I assumed here in below updated query that you need current month's results for recurrence events.

SPQuery query = new SPQuery();
query.ExpandRecurrence = true;
query.CalendarDate = new DateTime(2008,9,1);
query.Query = "<Where><DateRangesOverlap><FieldRef Name=\"EventDate\" /><FieldRef Name=\"EndDate\" /><Value Type=\"DateTime\"><Month /></Value></DateRangesOverlap></Where>";
3
  • yes that's true,and i tried the same query but tha is returning all recurrence events of the month ,means it shows expired events as well,which i dint want
    – Madhav
    Apr 18, 2016 at 10:01
  • Try adding two lines mentioned in my updated code above the query & try it
    – Hardik
    Apr 18, 2016 at 11:28
  • Thank you for ur kind help but unfortunately the result is still same
    – Madhav
    Apr 18, 2016 at 11:50
1

Resolved by applying below code

        using (SPSite spsite = SPContext.Current.Site)
            {
                using (SPWeb web = spsite.OpenWeb())
                {
                    SPList list = web.Lists["CalenderList"];
                    SPQuery query = new SPQuery();
                    query.ExpandRecurrence = true;
                    query.CalendarDate = DateTime.Now;
                    query.Query = @"<Where><DateRangesOverlap><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /><FieldRef Name='RecurrenceID' /><Value Type='DateTime'><Week /></Value></DateRangesOverlap></Where><OrderBy><FieldRef Name='EventDate' Ascending='True' /></OrderBy>",
                    ViewFields = "<FieldRef Name='Title'/><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /><FieldRef Name='fRecurrence' /><FieldRef Name='RecurrenceData' /><FieldRef Name='Location' />",
                    SPListItemCollection listItems = list.GetItems(query);
                    foreach (SPListItem items in listItems)
                    {
                         DateTime Checkdate = DateTime.Parse(item["EventDate"].ToString().Trim());
                         DateTime CurrentDate=DateTime.Now;
                         if (Checkdate.Date > CurrentDate.Date)
                         {
                            Console.WriteLine(items[3].ToString());                   
                            Console.ReadLine();
                         }
                   }
               }
           }
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.