2013-11-20 8 views
1

SharePoint의 SPView에 종속 외부 조회 필드를 추가하고 또한 의존 외부 조회를 추가 할 수 있었다 필드를 동일한 목록에 추가하십시오. 알아낼 수 없었던 것은 프로그래밍 방식으로 종속 외부 조회 필드를 목록의 기본보기에 추가하는 방법입니다.는 프로그래밍 내가 프로그래밍 방식으로 목록에 <strong><em>외부</em></strong> (즉, BDC) 조회 필드를 추가 할 수 있었다 2010

은 MSDN에 This 문서에서는 SPView에 정기적 의존 조회 필드를 추가하는 방법에 대한 예를 제공합니다 -하지만 나는 프로그래밍 SPView에 종속 외부 조회 필드를 추가하는 방법을 보여줍니다 예를 찾을 아직 .

다음은 SharePoint List에 종속 외부 조회 필드를 추가 할 때 사용하는 내 EventReceiver의 FeatureActivated 메서드에있는 코드이며 목록의 기본보기에 필드를 추가하려는 시도입니다.

var web = ((SPSite)properties.Feature.Parent).RootWeb; 
var list = web.Lists.TryGetList("MyList"); 
var fldName = "EmployeeID"; 

var fld = list.Fields.CreateNewField("BusinessData", fldName) as SPBusinessDataField; 

fld.SystemInstanceName = lobSystemInstanceName; 
fld.EntityNamespace = entityNamespace; 
fld.EntityName = entityName; 
fld.BdcFieldName = entityFieldName; 

//The dictionary object defined below contains key/value pairs that represent the 
//field name as a string along with a boolean flag that specifies whether or not 
//the secondary field should be added to the default view. 
var secondaryFieldNames = new Dictionary<string, bool>() 
         { 
          {"FirstName", true}, 
          {"LastName", true}, 
          {"Title", false} 
         } 
fld.SetSecondaryFieldsNames(secondaryFieldNames.Select(e => e.Key).ToArray()); 

var view = list.Views.DefaultView; 

foreach (var secFld in secondaryFieldNames) 
{ 
    var viewFieldName = String.Format("{0}: {1}", fldName, secFld.Key); 

    if (!view.ViewFields.Exists(viewFieldName) && secFld.Value) 
    { 
      view.ViewFields.Add(viewFieldName); 
      view.Update(); 
    } 
} 

앞서 언급했듯이 기본 조회 필드와 모든 보조 조회 필드가 목록에 추가되었습니다. 기본 조회 필드가 목록의 기본보기에 성공적으로 추가됩니다. 두 번째 필드는 그렇지 않습니다.

답변

0

변수에 뷰 필드 컬렉션을 저장하는 것은 나를위한 트릭이었습니다 (이유를 모르겠다).

foreach (var secFld in secondaryFieldNames) 
      { 
       var viewFieldName = String.Format("{0}: {1}", fldName, secFld.Key); 
       var viewFields = view.ViewFields; 
       if (!viewFields.Exists(viewFieldName) && secFld.Value) 
       { 
        viewFields.Add(viewFieldName); 
        view.Update(); 
       } 
      }