2012-07-25 2 views
0

사이트 사이트 루트 웹 사이트가 Main Site입니다. 2012 년, 2011 년 등 여러 하위 사이트가 있습니다. 루트 웹에는 Products라는 목록이 있습니다. 하위 사이트에는 Sales라는 목록이 있으며 루트 사이트의 제품 목록에 조회 필드를 추가해야합니다. 이 코드가 있지만 작동하지 않는 경우 조회 필드가 생성되었지만 제품이 있어도 드롭 다운이 비어 있습니다.RootWeb에서 목록에 조회 필드를 추가하십시오.

//Request North lookup 
       currentList = currentWeb.GetSafeListByName(SponsoringCommon.Constants.LISTNAMES_SALESNORTH); 
       string sFldReqNr = SponsoringCommon.Constants.FIELDS_REQUESTNUMBERLOOKUPNORTH_NAME + currentWeb.Title; 
       Functions.CreateRequestNumberLookup(currentList, sFldReqNr, false, Functions.NorthSouth.North); 

       ArrayList colPreviousContentTypes = new ArrayList(); 
       currentList.AddFieldToContentType(sFldReqNr, SponsoringCommon.Constants.CONTENTTYPES_SALESNUMBER_NAME, 2, colPreviousContentTypes, 1033); 




public static void CreateProductNameLookup(SPList currentList, string strInternalFieldName, bool allowMultipleValues) 
     { 
       Logger.LogDebug("Functions", 
       "CreateProductNameLookup(SPList currentList, string strInternalFieldName, bool allowMultipleValues)", "BEGIN"); 

      SPWeb currentWeb = currentList.ParentWeb; 
      SPList targetList = currentWeb.Site.RootWeb.GetSafeListByName(SponsoringCommon.Constants.LISTNAMES_PRODUCT_NAME); 
      SPFieldCollection colFields = currentList.Fields; 
      Guid targetListID = targetList.ID; 

      int L1 = strInternalFieldName.Length; 
      int L2 = currentWeb.Title.Length; 
      string sFieldNameWithoutYear = (strInternalFieldName.EndsWith(currentWeb.Title) ? 
       strInternalFieldName.Substring(0, L1 - L2) : 
       strInternalFieldName); 

      if (colFields.ContainsField(strInternalFieldName)) 
      { 
       Logger.LogDebug("Functions", 
        "CreateProductNameLookup(SPList currentList, string strInternalFieldName, bool allowMultipleValues)", 
        "Field '" + strInternalFieldName + "' already exists. (>> Skipped)"); 
      } 
      else 
      { 
       strInternalFieldName = colFields.AddLookup(strInternalFieldName, targetListID, false); 
       SPField fld = colFields.GetFieldByInternalName(strInternalFieldName); 
       fld.ShowInNewForm = true; 
       fld.ShowInEditForm = true; 
       fld.ShowInDisplayForm = true; 
       SPFieldLookup fldLU = fld as SPFieldLookup; 
       fldLU.AllowMultipleValues = allowMultipleValues; 
       string strSchemaXml = fldLU.SchemaXmlWithResourceTokens; 
       strSchemaXml = strSchemaXml.Replace("DisplayName=\"" + strInternalFieldName + "\"", "DisplayName=\"$Resources:SPNLSponsoring,Field_" + sFieldNameWithoutYear + "_Name;\""); 
       strSchemaXml = strSchemaXml.Replace("/>", " ShowField=\"" + targetList.Fields[SponsoringCommon.Constants.FIELDS_PRODUCT_NAMENEW].InternalName + "\" " + 
        "Description=\"$Resources:SPNLSponsoring,Field_" + sFieldNameWithoutYear + "_Description;\" " + 
        "Group=\"$Resources:SPNLSponsoring,Field_NationaleLoterijSponsoringColumns_Group;\" />"); 
       fldLU.SchemaXml = strSchemaXml; 
       fldLU.Update(true); 
       currentList.Update(); 
      } 

      Logger.LogDebug("Functions", 
       "CreateProductNameLookup(SPList currentList, string strInternalFieldName, bool allowMultipleValues)", "END"); 
     } 

답변

0

의 가능한 I는 parentweb.id를 수신하는 방법의 또 다른 addlookup 과부하를 사용했다 I 이미 그것을 해결

strInternalFieldName = colFields.AddLookup(strInternalFieldName, targetListID, currentWeb.Site.RootWeb.ID, true); 
then it works fine 
관련 문제