开发者

Sharepoint Content Query Web Part: Show items from "events" list that are set to occur or reoccur within a month

开发者 https://www.devze.com 2023-01-04 07:39 出处:网络
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

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)."


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消