2010-06-22 23 views
3

我正在創建一個使用SharePoint Web Services向用戶查詢和顯示Sharepoint列表的程序。我一次只能顯示一列,所以我需要找到一個「默認列」或「顯示列」來顯示。我知道「標題」常用於許多內容類型,但我希望這可以通過任何類型的自定義內容類型或列表進行強化,所以我想找到一些查詢列表的方法來發現此字段。Sharepoint列表中的列表項的正確顯示名稱/字段(使用Web服務)

例如:我在此處使用SharePoint Manager 2010並查看鏈接庫(它沒有標題字段),但不知何故,它知道該列表項名爲「http://google.com」。它是如何推斷的? alt text http://www.adamburkepile.com/upload/splist.png

+0

很好的問題 - 不知道答案,但裁判的,可以幫助 - 列出Web服務 http://msdn.microsoft.com/en-us/library/lists .lists.getlist(v = office.12).aspx 它將爲您提供CAML格式的列表架構,其中包括字段 http://msdn.microsoft.com/en-us/library/ms437580(v=office.12)的.aspx – Ryan 2010-06-23 10:09:06

回答

2

看起來像DisplayName有相當多的邏輯背後。下面是我使用的代碼反射:

public string DisplayName 
{ 
    get 
    { 
     if (!this.IsNew) 
     { 
      if ((!this.ParentList.AllowContentTypes && (this.ParentList.BaseType == SPBaseType.DocumentLibrary)) || (this.ParentList.AllowContentTypes && (this.ContentTypeId.IsNonDiscussionFolder || this.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.Document)))) 
      { 
       string str = (string) this.GetValue("BaseName", false); 
       if (!string.IsNullOrEmpty(str)) 
       { 
        return SPHttpUtility.HtmlDecode(str); 
       } 
      } 
      SPField fieldByInternalName = this.Fields.GetFieldByInternalName("Title", false); 
      if (fieldByInternalName != null) 
      { 
       string fieldValueAsText = fieldByInternalName.GetFieldValueAsText(this.GetValue(fieldByInternalName, -1, false)); 
       if (!string.IsNullOrEmpty(fieldValueAsText)) 
       { 
        return fieldValueAsText; 
       } 
      } 
      if (this.ParentList.AllowContentTypes) 
      { 
       if (this.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.Link)) 
       { 
        SPFieldUrlValue value2 = new SPFieldUrlValue((string) this.GetValue("URL", false)); 
        if (!string.IsNullOrEmpty(value2.Description)) 
        { 
         return value2.Description; 
        } 
        if (!string.IsNullOrEmpty(value2.Url)) 
        { 
         return value2.Url; 
        } 
       } 
       if (this.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.Message)) 
       { 
        Guid discussionTitleLookup = SPBuiltInFieldId.DiscussionTitleLookup; 
        SPField fld = this.Fields[discussionTitleLookup]; 
        string str3 = fld.GetFieldValueAsText(this.GetValue(fld, -1, false)); 
        if (!string.IsNullOrEmpty(str3)) 
        { 
         return str3; 
        } 
       } 
      } 
      if (this.ParentList.BaseType != SPBaseType.Survey) 
      { 
       using (IEnumerator enumerator = this.Fields.GetEnumerator()) 
       { 
        SPField field3; 
        string str5; 
        while (enumerator.MoveNext()) 
        { 
         field3 = (SPField) enumerator.Current; 
         if (field3.GetFieldBoolValue("TitleField")) 
         { 
          goto Label_00C6; 
         } 
        } 
        goto Label_016F; 
       Label_00BB: 
        if (!(field3 is SPFieldMultiLineText)) 
        { 
         return str5; 
        } 
        goto Label_00ED; 
       Label_00C6: 
        str5 = field3.GetFieldValueAsText(this.GetValue(field3, -1, false)); 
        if (string.IsNullOrEmpty(str5)) 
        { 
         goto Label_016F; 
        } 
        goto Label_00BB; 
       Label_00ED: 
        if (str5.Length <= 0xff) 
        { 
         return str5; 
        } 
        return str5.Substring(0, 0xff); 
       } 
      } 
      SPContext context2 = SPContext.Current; 
      if ((context2 == null) || (context2.FormContext.FormMode != SPControlMode.Edit)) 
      { 
       return SPResource.GetString("ViewResponseTitle", new object[] { this.ID.ToString("N0", this.Web.Locale) }); 
      } 
      return SPResource.GetString("ToolBarMenuRespondToSurvey", new object[0]); 
     } 
     SPContext current = SPContext.Current; 
     if (this.ParentList.BaseType != SPBaseType.Survey) 
     { 
      if ((current != null) && current.FormContext.IsNonDiscussionFolder) 
      { 
       return SPResource.GetString("ButtonTextNewFolder", new object[0]); 
      } 
      return SPResource.GetString("NewFormTitleNewItem", new object[0]); 
     } 
     return SPResource.GetString("ToolBarMenuRespondToSurvey", new object[0]); 
    Label_016F: 
     return SPResource.GetString("NoTitle", new object[0]); 
    } 
} 
相關問題