0

I have a field named Title in a link list (it's one of the default fields), but try as I might, I cannot programatically add it to the default view, edit, and new forms.

  • SharePoint Designer will probably not be an allowable approach. :(
  • Attempting to grab the views' ASPX reveals they stop short of defining which custom fields to display. I'm not surprised (there's probably some procedure to generate code to customize), but I'd rather avoid this if possible... I don't need anything too custom, just another field.

  • I tried the following code in C# (and an analog in PowerShell), but wasn't successful here either.

        SPField title = linkList.Fields["Title"];
        title.ShowInDisplayForm = true;
        title.ShowInEditForm = true;
        title.ShowInNewForm = true;
        title.ShowInViewForms = true;
        title.Update();
    

tl;dr how do I add an existing field to a form?

0

You should use:

var title = linkList.Fields.GetFieldByInternalName("Title");
title.ReadOnlyField = false;
title.SchemaXML = title.SchemaXML.Replace("Hidden=\"TRUE\"","Hidden=\"FALSE\"");
title.Update();

Firstly internally there are four columns with the display name of "Title" in the Links list so it's possible for you to pick up the wrong one with that code. Fortunately the internal names are different. For reference the internal names are:

  • Title - Text - The one your after
  • LinkTitleNoMenu - Computed - Used on views
  • LinkTitle - Computed - Used on views
  • Survey Title - Not idea why this is in a Links list:-)

Secondly you can't just set title.Hidden = true; because it will get blocked (partly because the field is read only but also because changes are blocked anyway). This means the only way to make this change is to alter the schemaXML for the field.

That also brings me onto the subject of making this change in the first place. As Microsoft have locked this down so much there may be something that may bite you later e.g. when you upgrade this site to the next version of SharePoint. So you may want to consider using a new single line text field anyway with a similar name e.g. "Link Title".

0

Try this

var title = linkList.Fields[SPBuiltInFieldId.Title];
title.ShowInDisplayForm = true;
title.ShowInEditForm = true;
title.ShowInNewForm = true;
title.ShowInViewForms = true;
title.Update();
  • The first line is the most useful here (SPBuiltInFieldId). Unfortunately the other ones are basically what I've tried, and are ineffective. – user22303 Sep 18 '14 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy