2009-06-17 3 views
0

このクエリをWebアプリケーションと同じサーバーで実行しているので、SPQuery.ExpandRecurrenceが機能するはずです。しかし、以下の場合、返されたリストコレクションに3つのアイテムと3つのアイテムと再発生がありますが、そのすべては現在の月に含まれます。定期的なSharePointカレンダーリストアイテムを取得するには

Stramit Caml Viewerで照会が動作していることを確認し、同じ3つの項目を返します。

わかりやすいものが紛れていると教えてください。

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); 
    } 

答えて

2

私はカレンダーアイテムのクエリに慣れていませんが、SPQery.Queryプロパティには<Query>タグを使用する際に問題がありました。

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

アメージング、以下のようにカスタムクエリにVIEWNAMEタイを渡すことをお勧めします:それはあなたがこれらの2行を削除した場合に正しく動作しません。本当にありがとう! – Marc

0

あなたはどのようなリストビューを使用していますか?

アイテムを取得しているビューを指定していないため、デフォルトビューからクエリ結果を取得しています。

デフォルトのビューはカレンダービュー以外のものですか? ExpandRecurrenceはカレンダービューでのみ機能し、他のビューでは機能しません。

1

それはそれはそれが動作するようになりまし必要だったことすべて、だった

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; 
} 
関連する問題