R – How to get recurring SharePoint Calendar List Items

camlsharepointspquery

Im running this query on the same server as the web application, so SPQuery.ExpandRecurrence should work. However, with the following I only get 3 items in the returned list collection vs. the 3 items and the re-occurrences, all of which fall within the current month.

I did verify with Stramit Caml Viewer that the query works, and returns the same 3 items.

Please tell me I'm missing something blatenly obvious?

    static SPListItemCollection GetSourceColl(SPList list)
    {
        SPQuery query = new SPQuery();
        query.ExpandRecurrence = true;
        query.CalendarDate = new DateTime(DateTime.Now.Year,DateTime.Now.Month, 1);

        System.Text.StringBuilder oSb = new System.Text.StringBuilder();

        oSb.Append("     <Query xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">");
        oSb.Append("         <Where>");
        oSb.Append("              <And>");
        oSb.Append("                   <DateRangesOverlap>");
        oSb.Append("                        <FieldRef Name=\"EventDate\" />");
        oSb.Append("                        <FieldRef Name=\"EndDate\" />");
        oSb.Append("                        <FieldRef Name=\"RecurrenceID\" />");
        oSb.Append("                        <Value Type=\"DateTime\">");
        oSb.Append("                             <Month />");
        oSb.Append("                        </Value>");
        oSb.Append("                   </DateRangesOverlap>");
        oSb.Append("                   <And>");
        oSb.Append("                        <And>");
        oSb.Append("                             <Eq>");
        oSb.Append("                                  <FieldRef Name=\"Status\" />");
        oSb.Append("                                  <Value Type=\"Text\">Finalized</Value>");
        oSb.Append("                             </Eq>");
        oSb.Append("                             <Leq>");
        oSb.Append("                                  <FieldRef Name=\"DistributionStartDate\" />");
        oSb.Append("                                  <Value Type=\"DateTime\">");
        oSb.Append("                                       <Today />");
        oSb.Append("                                  </Value>");
        oSb.Append("                             </Leq>");
        oSb.Append("                        </And>");
        oSb.Append("                        <Neq>");
        oSb.Append("                             <FieldRef Name=\"Distribution\" />");
        oSb.Append("                             <Value Type=\"Text\">Intranet</Value>");
        oSb.Append("                        </Neq>");
        oSb.Append("                   </And>");
        oSb.Append("              </And>");
        oSb.Append("         </Where>");
        oSb.Append("    </Query>");
        query.Query = oSb.ToString();

        return list.GetItems(query);
    }

Best Answer

I'm not familiar with querying calendar items, however I've had problems using the <Query> tags for the SPQuery.Query property. Does it work correctly if you remove these two lines:

oSb.Append("<Query xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">");
...
oSb.Append("</Query>");
Related Topic