2013-06-06 7 views
0

PHP에서 제공되는 PHP는 실제로 신경 쓰지 않기 때문에 특정 유형을 할당하거나 반환하는 데 익숙하지 않습니다. 그러나 자바와 C#의 세계로 돌아와서이 언어들이주의를 기울인다. 당신이이 타입을 전달할 때 그 타입을 기대한다고하자. 그래서 내가 무엇을 잘못하고 않는 나는 내가 만들 수있는 방법이 유형 SPList 내가 같은 매우 기본적인 기능을 가지고C#, 메서드는 목록을 만들지 만 형식 목록이 아닙니다.

의 수 :

protected void createNewList(SPFeatureReceiverProperties properties) 
    { 
     Dictionary<string, List<AddParams>> param = new Dictionary<string, List<AddParams>>(); 

     // Create the keys 
     param.Add("Name", new List<AddParams>()); 
     param.Add("Type", new List<AddParams>()); 
     param.Add("Description", new List<AddParams>()); 

     // Set the values 
     param["Name"].Add(new AddParams { type = SPFieldType.Text, required = true }); 
     param["Type"].Add(new AddParams { type = SPFieldType.Text, required = true }); 
     param["Description"].Add(new AddParams { type = SPFieldType.Text, required = true }); 

     // Create the really simple List. 
     new SPAPI.Lists.Create(properties, param, "Fake List", "Sample Description", SPListTemplateType.GenericList, "Sample View Description"); 
    } 

이 당신에게 목록을 작성하는 SharePoint 2010의 웹 파트가 활성화되면 목록에 추가합니다. 이름은 가짜 목록이며, 우리는 존경받는 매개 변수를 사용하여 일부 collumn을 전달합니다. 이 SPAPI.Lists.Create 방법을 살펴 봅시다 :

public Create(SPFeatureReceiverProperties properties, Dictionary<string, List<AddParams>> columns, 
     string name, string description, SPListTemplateType type, string viewDescription) 
    { 

     SPSite siteCollection = properties.Feature.Parent as SPSite; 
     if (siteCollection != null) 
     { 
      SPWeb web = siteCollection.RootWeb; 
      Guid Listid = web.Lists.Add(name, description, type); 
      web.Update(); 

      // Add the new list and the new content. 
      SPList spList = web.Lists[name]; 
      foreach(KeyValuePair<string, List<AddParams>> col in columns){ 
       spList.Fields.Add(col.Key, col.Value[0].type, col.Value[0].required); 
      } 

      spList.Update(); 

      //Create the view? - Possibly remove me. 
      System.Collections.Specialized.StringCollection stringCollection = 
       new System.Collections.Specialized.StringCollection(); 

      foreach (KeyValuePair<string, List<AddParams>> col in columns) 
      { 
       stringCollection.Add(col.Key); 
      } 

      //Add the list. 
      spList.Views.Add(viewDescription, stringCollection, @"", 100, 
       true, true, Microsoft.SharePoint.SPViewCollection.SPViewType.Html, false); 
      spList.Update(); 
     } 
    } 

을 우리 모두는 셰어에 사용하기 위해 SPList 개체를 만드는 일을 한 것을 여기에서 볼 수 있습니다. 배포가 끝나면 페이지에 추가 할 수있는 새로운 목록이 생깁니다. 그래서 문제가 뭐야?

PHP에서 나는을 SPList 유형의 객체를 요청하는 함수에 전달할 수 있으며, 뭔가 빠뜨리지 않는 한 작동 할 것입니다.>> 여기에 SPList가 사라지지 않습니다.

그래서 내 질문은 :

내가 그래서 둘 수있는 SPLIst 개체 목록을 작성하고 돌려주는 변경해야합니까?은 다음과 같이 간단합니다. return new SPAPI.Lists.Create(properties, param, "Fake List", "Sample Description", SPListTemplateType.GenericList, "Sample View Description");

나에게 맞는 것처럼 보입니다.

업데이트

SPList에 메소드 서명을 켜기 및 return new .... 작동하지 않았다 복귀.

+3

당신은'Create'라는 클래스의 * 생성자 *를 호출 한 것으로 나타났습니다. 그것은 좋은 생각처럼 보이지 않습니다. 네가 여기서 뭘하려고하는지 분명치 않다. –

답변

0

당신은 모두 당신의 방법에서 SPList를 반환해야합니다

protected SPList createNewList(SPFeatureReceiverProperties properties) 
{ 
    //Do the stuff 

    SPList result = new SPAPI.Lists.Create(properties, param, "Fake List", "Sample Description", SPListTemplateType.GenericList, "Sample View Description"); 
    return result; 
} 

public SPList Create(SPFeatureReceiverProperties properties, Dictionary<string, List<AddParams>> columns, 
    string name, string description, SPListTemplateType type, string viewDescription) 
{ 
    // Do the stuff 

    return spList; 
}