Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

web services - Expand Recurring Events from a Sharepoint Calendar over WebServices?

Is it possible to get a list of events (with recurring events expanded) out of Sharepoint's Calendar using the Web Service exposed through Lists.aspx?

This is evidently possible if you are using C# or VB, as described here using a snippet like this:

SPQuery query = new SPQuery();
query.ExpandRecurrence = true;
query.Query = "<Where><DateRangesOverlap><FieldRef Name="EventDate" /><FieldRef Name="EndDate" /><FieldRef Name="RecurrenceID" /><Value Type="DateTime"><Month /></Value></DateRangesOverlap></Where>";

I am trying to do the same using plain XML via cURL with this query:

<GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<listName>{my guid goes here}</listName>
<query>
    <Query xmlns="">
    <Where>
    <DateRangesOverlap>
      <FieldRef Name="EventDate" />
      <FieldRef Name="EndDate" />
      <FieldRef Name="RecurrenceID" />
      <Value Type="DateTime"><Month/></Value>
   </DateRangesOverlap>
    </Where>
    </Query>
</query>
<queryOptions>
    <QueryOptions>
    <ExpandRecurrence>TRUE</ExpandRecurrence>
    </QueryOptions>
</queryOptions>

This kinda works - it gets all the list items, but recurring items are not expanded. The key seems to be the ExpandRecurrence property. Surprisingly, Google does not seem to have a lot to say on the matter beyond a couple of blog posts. Scouring the web, I've read a few comments indicating that the ExpandRecurrence property does not work, but others say it works fine and nothing I've read has struck me as definitive.

Has anybody tried this and gotten it to work without using C# or VB - just straight XML?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Finally got this to work correctly and return all recurrent events on a SharePoint Calendar. Here is the XML for the Web Service Query:

<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>
<listName>{your GUID goes here}</listName>
<query>
 <Query>
  <Where>
   <DateRangesOverlap>
    <FieldRef Name="EventDate" />
    <FieldRef Name="EndDate" />
    <FieldRef Name="RecurrenceID" />
    <Value Type='DateTime'><Year/></Value>
   </DateRangesOverlap>
  </Where>
 </Query>
</query>
<queryOptions>
 <QueryOptions>
  <ExpandRecurrence>TRUE</ExpandRecurrence>
 </QueryOptions>
</queryOptions>
</GetListItems>

The key was not only setting the ExpandRecurrence option to true - you also have to include the value in the DateRangeOverlap to Year.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...