[SharePoint 2007/2010]Query SharePoint Calendar Event

首先要搞清楚日历事件的各种类型,参考文章:

http://sharepoint.microsoft.com/blog/Pages/BlogPost.aspx?PageType=4&ListId={72C1C85B-1D2D-4A4A-90DE-CA74A7808184}&pID=761

TypeDescriptionfRecurrencefAllDayEventEventType
Single event

An event created with the All Day Event and

Recurrence checkboxes unselected.

FALSEFALSE0
All-day event

An event created with the All Day Event

checkbox selected.

FALSETRUE0
Recurring event

An event created with the Recurrence checkbox selected. 

 Has a recurrence icon in the All Events view. 

 Appears as a single master event on the All Events view,

but as recurring instances on the Current Events and

Calendar views.

TRUEFALSE1
Recurring all-day event

Same as above, but with the All Day Event checkbox

selected at creation time.

TRUETRUE1
Recurrence exception

Created by editing an instance of a recurring event.  

Has a strikethrough recurrence icon in the All Events view.

TRUEFALSE4
All-day recurrence exception

Same as above, but created by editing an instance of an

all-day recurring event.

TRUETRUE4

Deleted instance of a

recurring event

Created by deleting a instance of a recurring event.  

Title is prefixed with “Deleted:” in the All Events view,

and is hidden in the Current Events and Calendar views.

TRUEFALSE3

Deleted instance of an

all-day recurring event

Same as above, but created by deleting an instance of

an all-day recurring event.

TRUETRUE3

  重复事件

FieldValue for single eventValue for recurring event
EventDateStart date and time

Start date and time set for the recurring event when it was created,

which may be an earlier date than the first instance of the recurring event.

EndDateEnd date and time

End date and time for the last instance of the recurring event.  

For recurring events with no end date, this is a computed date

several years in the future.

Duration

The time in seconds between EventDate

and EndDate. 

The duration in seconds of an individual instance of the recurring event.

  特例事件和已删除事件

FieldValue for exception or deleted instance
MasterSeriesItemID

The ID of the recurring event from which this exception

or deleted instance was made.

RecurrenceID

The date and time of the instance of the recurring event which this exception

or deleted instance takes the place of.

  重复事件的重复模式

Recurrence typeRecurrenceData field value
Daily every 1 days, no end date

<recurrence>

  <rule>

    <firstDayOfWeek>su</firstDayOfWeek>

    <repeat><daily dayFrequency="1" /></repeat>

    <repeatForever>FALSE</repeatForever>

  </rule>

</recurrence>

Weekly every Monday, Tuesday,

and Wednesday, end by 5/31/2007

<recurrence>

  <rule>

    <firstDayOfWeek>su</firstDayOfWeek>

    <repeat>

      <weekly mo="TRUE" tu="TRUE" we="TRUE" weekFrequency="1" />

    </repeat>

    <windowEnd>2007-05-31T22:00:00Z</windowEnd>

  </rule>

</recurrence>

Monthly the third Wednesday of every 2 months,

no end date

<recurrence>

  <rule>

    <firstDayOfWeek>su</firstDayOfWeek>

    <repeat>

      <monthlyByDay we="TRUE" weekdayOfMonth="third" monthFrequency="2" />

    </repeat>

    <repeatForever>FALSE</repeatForever>

  </rule>

</recurrence>

Yearly every May 18, end after 10 instances

<recurrence>

  <rule>

    <firstDayOfWeek>su</firstDayOfWeek>

    <repeat><yearly yearFrequency="1" month="5" day="18" /></repeat>

    <repeatInstances>10</repeatInstances>

  </rule>

</recurrence>

虽然事件的重复模式是以XML格式储存,但在使用ClientObjectModel查询时,并不需要手动去解析XML。

使用SPQuery对象查询时,需指定以下属性:

ExpandRecurrence -- 是否展开重复事件

CalendarDate -- 指定查询的参考时间

查询每日事件

 1             using (SPSite site = new SPSite(siteUrl))
 2             {
 3                 using (SPWeb web = site.OpenWeb())
 4                 {
 5                     SPList calendar = web.GetList(listUrl);
 6                     SPQuery caml = new SPQuery();
 7                     caml.Query = @"<Where>
 8                                     <DateRangesOverlap>
 9                                         <FieldRef Name='EventDate' />;
10                                         <FieldRef Name='EndDate' />
11                                         <FieldRef Name='RecurrenceID' />
12                                         <Value Type='DateTime'><Today /></Value>
13                                     </DateRangesOverlap>
14                                 </Where>";
15 
16                     caml.ExpandRecurrence = true;
17                     caml.CalendarDate = DateTime.Now;
18 
19                     return calendar.GetItems(caml);
20                 }
21             }

 

查询每周事件

1                     caml.Query = @"<Where>
2                                     <DateRangesOverlap>
3                                         <FieldRef Name='EventDate' />;
4                                         <FieldRef Name='EndDate' />
5                                         <FieldRef Name='RecurrenceID' />
6                                         <Value Type='DateTime'><Week /></Value>
7                                     </DateRangesOverlap>
8                                 </Where>";

 

查询每月事件

1                     caml.Query = @"<Where>
2                                     <DateRangesOverlap>
3                                         <FieldRef Name='EventDate' />;
4                                         <FieldRef Name='EndDate' />
5                                         <FieldRef Name='RecurrenceID' />
6                                         <Value Type='DateTime'><Month /></Value>
7                                     </DateRangesOverlap>
8                                 </Where>";

 

查询每年事件

1                     caml.Query = @"<Where>
2                                     <DateRangesOverlap>
3                                         <FieldRef Name='EventDate' />;
4                                         <FieldRef Name='EndDate' />
5                                         <FieldRef Name='RecurrenceID' />
6                                         <Value Type='DateTime'><Year /></Value>
7                                     </DateRangesOverlap>
8                                 </Where>";

 

转载于:https://www.cnblogs.com/s1nce/p/Query-SharePoint-Calendar-Event.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值