Frage

Here is the code I use:

SPQuery query = new SPQuery();
query.ExpandRecurrence = true;
query.CalendarDate = new DateTime(2013, 1, 1);
query.Query = @"
<Where>
        <DateRangesOverlap>
            <FieldRef Name=""EventDate"" />
            <FieldRef Name=""EndDate"" />
            <FieldRef Name=""RecurrenceID"" />
            <Value Type=""DateTime"">
                <Year />
            </Value>
        </DateRangesOverlap>
</Where>";
var items = list.GetItems(query);

In the case I have an item that starts at 01/01/2012 and ends at 01/01/2030 with a recurrence every Tuesday, the query returns all items from today until today+year. That means that if today is 18th January 2012, the query isn't returning items from 19th January 2013.

What I need are all items in 2013 (I don't care about other year items, but it would be better not to return them for performance issues). What is happening and how can I solve it?

UPDATE: After some tests I have detected a couple strange things:

If I use Year, the query returns what I have explained before.

If I use Month instead, the query returns all single events in CalendarDate's month. Also, it returns some events outside the month (one or two at most).

If I use Today, it returns all single events until today+2years.

I can't understand this behavior, but waiting for a better answer I will call 12 times the query using Month. Luckily, we don't have too many items... I can't

War es hilfreich?

Lösung

My colleague and I call this type of query, "Recurrance Expansion". It is SharePoints way of expanding recurring events to display on the calendar week and month views for all events (recurring and non recurring).

We have found that doing the queries larger than a month are not dependable and results get throttled depending on number of events or the size of the data being returned or mood of the server.

We have found good results when dealing with one month increments. So go with your plan to do 12 month queries. Its a pain, but the only way we could get it to work.

One thing to watch when you are doing these month queries is that SharePoint will return boundry events that fall just outside of the beginning and end of the month. This is to compensate for the month view display where you show the events at the beginning of the week, even though they are not included in the month you desire. (see Leap Day Event from Feb that shows up in the March query in below image). So use Except or some other set logic in your code to remove duplicates from the 12 queries.

boundry events

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit sharepoint.stackexchange
scroll top