The correct display name / field for the list item in the Sharepoint list (using web services)

I am creating a program that uses SharePoint web services to query and display a Sharepoint list for a user. I can only show one column at a time, so I need to find the "default column" or "display column" to display. I know that “Heading” is commonly used in many types of content, but I want it to be resistant to any type of custom content type or list, so I would like to find some way to query the list to find this field.

For example: I use SharePoint Manager 2010 here and look at the link library (which does not have a header field), but somehow it knows that the list item is called " http://google.com ". How does this get it out? (source: adamburkepile.com )alt text

+3
source share
1 answer

DisplayName seems to have quite a bit of logic. Here is the code I got with 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]);
    }
}
+2
source

Source: https://habr.com/ru/post/1751270/


All Articles