zoukankan      html  css  js  c++  java
  • [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

    Type Description fRecurrence fAllDayEvent EventType
    Single event

    An event created with the All Day Event and

    Recurrence checkboxes unselected.

    FALSE FALSE 0
    All-day event

    An event created with the All Day Event

    checkbox selected.

    FALSE TRUE 0
    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.

    TRUE FALSE 1
    Recurring all-day event

    Same as above, but with the All Day Event checkbox

    selected at creation time.

    TRUE TRUE 1
    Recurrence exception

    Created by editing an instance of a recurring event.  

    Has a strikethrough recurrence icon in the All Events view.

    TRUE FALSE 4
    All-day recurrence exception

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

    all-day recurring event.

    TRUE TRUE 4

    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.

    TRUE FALSE 3

    Deleted instance of an

    all-day recurring event

    Same as above, but created by deleting an instance of

    an all-day recurring event.

    TRUE TRUE 3

      重复事件

    Field Value for single event Value for recurring event
    EventDate Start 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.

    EndDate End 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.

      特例事件和已删除事件

    Field Value 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 type RecurrenceData 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>";
  • 相关阅读:
    开发常见错误之 :Missing artifact com.sun:tools:jar 1.7.0
    开发常见错误之 : Detected both log4j-over-slf4j.jar AND slf4j-log4j12.jar
    kafka集群部署
    kafka
    Oracle 学习之触发器
    CloudSetuper
    erlang :打开界面工具的命令
    erlang 二进制中 拼接 变量或者函数 报错
    Python内部机制。
    AOP (面向切面编程)
  • 原文地址:https://www.cnblogs.com/s1nce/p/Query-SharePoint-Calendar-Event.html
Copyright © 2011-2022 走看看