代码之家  ›  专栏  ›  技术社区  ›  ACBurk

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

  •  3
  • ACBurk  · 技术社区  · 14 年前

    例如:我在这里使用sharepointmanager2010,查看一个链接库(没有标题字段),但不知怎么的,它知道列表项被称为 http://google.com '. 这是怎么推断的? alt text
    (来源: adamburkepile.com )

    1 回复  |  直到 5 年前
        1
  •  2
  •   Kit Menke    14 年前

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