Domanda

Sto eseguendo questa query sullo stesso server dell'applicazione Web, quindi SPQuery.ExpandRecurrence dovrebbe funzionare. Tuttavia, con quanto segue ottengo solo 3 articoli nella raccolta di elenchi restituiti rispetto ai 3 articoli e alle ricorrenze, tutti rientranti nel mese corrente.

Ho verificato con Stramit Caml Viewer che la query funziona e restituisce gli stessi 3 elementi.

Per favore, dimmi che mi manca qualcosa di palesemente ovvio?

    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);
    }
È stato utile?

Soluzione

Non ho familiarità con l'interrogazione degli elementi del calendario, tuttavia ho riscontrato problemi nell'utilizzo dei tag <Query> per la proprietà SPQuery.Query. Funziona correttamente se rimuovi queste due righe:

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

Altri suggerimenti

È consigliabile passare il legame ViewName alla query personalizzata come mostrato di seguito

    private SPListItemCollection GetSourceColl(SPList list, string viewName)
{
    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();
    SPListItemCollection itemColl = null;
    if (string.IsNullOrEmpty(viewName))
    {
        itemColl = list.GetItems(query);
    }
    else
    {
        itemColl =  list.GetItems(query, viewName);
    }
    return itemColl;
}

Ehi, quale visualizzazione elenco stai usando?

Dal momento che non si specifica la vista da cui si stanno recuperando gli elementi, si stanno raccogliendo i risultati della query dalla vista predefinita.

Qualche possibilità che la vista predefinita sia diversa da una vista calendario? Perché penso che ExpandRecurrence funzioni solo per le visualizzazioni del calendario e non per altre visualizzazioni.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top