views:

1002

answers:

2

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/\"&gt;");
        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);
    }
A: 

Hey what list view are you using?

Since you are not specifying the view from which you are retrieving the items, it is picking up the query results from the default view.

Any chance your default view is anything other than a calendar view? Because i think the ExpandRecurrence work only for calendar views and not any other views.

ashwnacharya
+2  A: 

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/\"&gt;");
...
oSb.Append("</Query>");
Alex Angas
Amazing, that was all that was needed, it works now. Thanks so much!
Marc