2012-06-19 1 views
4

Client OM을 사용하여 목록을 쿼리 할 때로드 할 항목 필드 목록을 dinamically 생성/지정하려면 어떻게합니까?Sharepoint 2010 클라이언트를 사용하여로드 할 항목 필드 지정 OM

이것은 CAML 쿼리에서 태그를 사용하여 수행 할 수 있지만 원하지 않는 필드가 추가로로드되어 페이로드가 커집니다. 여기를 참조하십시오 : http://blogs.technet.com/b/speschka/archive/2009/11/01/using-the-sharepoint-2010-client-object-model-part-3.aspx

여기에 사용하는 테스트 코드의 메신저입니다 :

ClientContext clientContext = new ClientContext("http://myserver/sites/mysite"); 
Web site = clientContext.Web; 

List list = clientContext.Web.Lists.GetByTitle("MyList"); 
CamlQuery camlQuery = new CamlQuery(); 
camlQuery.ViewXml = "<View Scope='RecursiveAll'><RowLimit>100</RowLimit></View>"; 
ListItemCollection listItems = list.GetItems(camlQuery); 

clientContext.Load(listItems, 
     items => items.ListItemCollectionPosition, 
     items => items.Include(
       item => item["ID"], 
       item => item["Title"] 
      )); 

clientContext.ExecuteQuery(); 

는 내가하고 싶은 것은 람다 식의 런타임에 포함 방법을 생성하는 것입니다. 아직도 운이 없다. 내가 시도하는 모든 솔루션에서 "쿼리식이 지원되지 않습니다."라는 오류 메시지가 나타납니다.

답변

0

나중에 쿼리 할 열이있는 특정 뷰를 만들고 GetItems 메서드를 호출 할 때 해당 뷰를 사용할 수 있습니다.

0

무료 CAMLDesigner (http://sharepoint.biwug.be/SitePages/Caml_Designer.aspx)를 추천합니다. caml을 만들고 멋진 GUI로 결과를 확인할 수 있습니다.

var array = new string[] { "ID", "Title" }; // define dynamically, this is just an example 
foreach (var field in array) 
{ 
    clientContext.Load(listItems, includes => includes.Include(i => i[field])); 
} 

생성 된 쿼리가 exacly 하나에 여러 람다 표현식과 동일합니다 : 당신이 동적으로 루프에서 각 필드를로드 할 수 있습니다 CamlQuery를 통해로드 필드를 지정하려면

https://sharepoint.stackexchange.com/a/69172/5170

0

메소드로드.

clientContext.Load(listItems, includes => includes.Include(i => i["ID"], i => i["Title"])); 

모두 생성 쿼리

<Query Id="#" ObjectPathId="#"> 
    <Query SelectAllProperties="false"> 
     <Properties /> 
    </Query> 
    <ChildItemQuery SelectAllProperties="false"> 
     <Properties> 
      <Property Name="ID" ScalarProperty="true" /> 
      <Property Name="Title" ScalarProperty="true" /> 
     </Properties> 
    </ChildItemQuery> 
</Query> 
관련 문제