views:

468

answers:

1

I've been reading this msdn post: http://msdn.microsoft.com/en-us/library/aa981241.aspx

trying to edit the content query web part to only show items from the event list which either occur within 30 days or reoccur within 30 days. It is straight forward to deal with events which do not reoccur because I can compare [Start Date] to [Today]+30 with the modify this shared web part configuration, but for reocurring events it seems that [Start Date] and [End Date] describe the period over which the reocurring event is to occur, and I don't know what to do to determine the soonest upcoming reoccurance of an event. The cqwp only takes three filter items, so I can't deal with both recurring and single occurance items without overriding the query.

I think the field I need to use for reoccurrance is one of these: msdn-microsoft-com/en-us/library/microsoft.sharepoint.spfieldrecurrence_members.aspx but none of them seem appropriate.

How do you deal with the "fourth day of the month" reocurrance msdn-microsoft-com/en-us/library/microsoft.sharepoint.weekofmonth.aspx

Basically, how do you override the query to filter reocurring and single occurance events to show only those which occur within a week?

I've added the following code to the CQWP .webpart file:

<Where>
<Or>
<And>
  <Neq>
    <FieldRef Name="FRecurrence"/>
    <Value Type="Recurrance">1</Value>
  </Neq>
  <And> 
    <Lt>
      <FieldRef Name="EventDate" Type="DateTime"/>
      <Value Type="DateTime"><Today OffsetDays="30"/></Value>
    </Lt>
    <Gt>
     <FieldRef Name="EventDate" Type="DateTime"/>
    <Value Type="DateTime"><Today /></Value>
    </Gt>
  </And>
</And>
<DataRangesOverlap>
  <FieldRef Name="EventDate" />
  <FieldRef Name="EndDate" />
  <FieldRef Name="RecirrenceId" />
  <Value Type="DateTime"><Month /></Value>
</DataRangesOverlap>
</Or>   
</Where>

but my page is returning: "Unable to add selected web part(s). The file format is not valid. Try importing a Web Part file (.WebPart)."

+1  A: 

SharePoint recurring events are tricky. This post is the single best resource for understanding the mess of recurring events

Understanding the SharePoint calendar and how to export it to iCal format

I don't think you're going to be able to do this in a CEWP but you can get the recurrences using something like

    SPList list = oSPWeb.GetList(listGuid);
    SPQuery query = new SPQuery();
    query.ExpandRecurrence = true;
    query.CalendarDate = new DateTime(2010, 6, 17);

    query.Query = "<Where><DateRangesOverlap><FieldRef Name=\"EventDate\" /><FieldRef Name=\"EndDate\" /><FieldRef Name=\"RecurrenceID\" /><Value Type=\"DateTime\"><Week /></Value></DateRangesOverlap></Where>";
    SPListItemCollection listItems = list.GetItems(query);
    foreach (SPListItem items in listItems)
    {
        // items["EventDate"].ToString()
    }

Then you will get recurring and non-recurring events that occur this week.

But beware that this is designed to be used by the calendar view so if you do, for example,

query.CalendarDate = new DateTime(2010, 6, 17);
query.Query = "<Where><DateRangesOverlap><FieldRef Name=\"EventDate\" /><FieldRef Name=\"EndDate\" /><FieldRef Name=\"RecurrenceID\" /><Value Type=\"DateTime\"><Month /></Value></DateRangesOverlap></Where>";

(Notice the Month setting) then you will get all events that should appear on this months calendar view - that is 31st May 2010 to 4th July 2010.

Ryan
Thanks for your reply, Ryan.I used your DateRangesOverLap identifier. But I think my edit is closer to where I want to be.Is there any way to replace <Month /> with a range like <Today:Today OffsetDays="30"/> ?
Jack
I don't think you're going to be able to this via a CQWP - you can't set query.ExpandRecurrances. I think you're going to have to code a web part.
Ryan
re: <Today the format should be <Today Offset="10" /> but again I don't think this is going to work. The ExpandRecurrances is designed to support the calendar views which need daily/weekly and monthly views - not arbitrary 10 day views. You're going to have to get all code monkey on this ;)
Ryan
I've switched my site to drupal, because calendars create views more naturally in drupal. Also, a file system can be configured with the file framework module and webdev well enough to do what sharepoint can. Drupal just allows for easy extension in a way sharepoint doesn't.
Jack