Sharepoint列表中列表项的正确显示名称/字段(使用Web服务)

时间:2010-06-22 20:04:31

标签: web-services sharepoint list

我正在创建一个程序,该程序使用SharePoint Web Services查询并向用户显示Sharepoint列表。我一次只能显示一列,所以我需要找到一个'默认列'或'显示列'来显示。我知道'Title'常用于许多内容类型,但我希望它对任何类型的自定义内容类型或列表都很健壮,所以我想找到一些查询列表来发现这个字段的方法。

例如:我在这里使用SharePoint Manager 2010并查看链接库(没有标题字段)但不知何故它知道列表项称为“http://google.com”。怎么推断这个? alt text http://www.adamburkepile.com/upload/splist.png

1 个答案:

答案 0 :(得分:2)

看起来DisplayName背后有相当多的逻辑。这是我使用Reflector获得的代码:

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]);
    }
}