Add custom field to List - Programmatically - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Add custom field to List - Programmatically

  • Add custom field to List - Programmatically
  • Hi,
    i created a list with this block of code:
                    .Do(l =>
                        // Set the list properties
                        l.Title = listTitle;
                        l.Description = listDescription;
                        l.UrlName = Regex.Replace(supplierListTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
                        l.DateCreated = DateTime.Now;

    How can i add two custom fields to the list?
    1º Email (string)
    2º Contacts (string)

    Another question:
    Why custom fields are common to all lists? is unnatural that kind of option, no?

    Thanks for the help
  • Hello Nuno,

    Please refer to this documentation on creating custom fields using the API.
    Adding custom fields for only one list is not possible. When a custom field is added it applies to all lists. The same rule applies for all content modules in Sitefinity because custom fields are tied to a object type rather than a single row of data. Consider a scenario how each row (in the same table) would have different columns, which is not possible by database rules so custom fields per row (or list in this case) is not possible as well.

    All the best,
    Venkata Koppaka
    the Telerik team
  • Thanks.

  • Hi Venkata,

    If I have created some custom fields in List Itmes then can I access them using fluent API?


    Harshil Shukla

  • Hello Harshil,

    The following article shows how you can access custom fields: Getting the value of a custom field

    Nadezhda Petrova
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items