+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Add custom field to List - Programmatically

Add custom field to List - Programmatically

5 posts, 0 answered
  1. Nuno
    Nuno avatar
    9 posts
    Registered:
    04 Jan 2013
    24 Jan 2013
    Link to this post
    Hi,
    i created a list with this block of code:
             App.WorkWith().List().CreateNew(listID)
                    .Do(l =>
                    {
                        // Set the list properties
                        l.Title = listTitle;
                        l.Description = listDescription;
                        l.UrlName = Regex.Replace(supplierListTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");
                        l.DateCreated = DateTime.Now;
                    })
                    .SaveChanges();

    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
  2. Venkata Koppaka
    Venkata Koppaka avatar
    67 posts
    Registered:
    24 Sep 2012
    24 Jan 2013
    Link to this post
    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
  3. Nuno
    Nuno avatar
    9 posts
    Registered:
    04 Jan 2013
    25 Jan 2013
    Link to this post

    Thanks.


  4. Harshil
    Harshil avatar
    5 posts
    Registered:
    19 Mar 2014
    11 Jul 2014
    Link to this post

    Hi Venkata,

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

    Regards,

    Harshil Shukla

  5. Nadezhda Petrova
    Nadezhda Petrova avatar
    20 posts
    Registered:
    28 Oct 2016
    14 Jul 2014
    Link to this post
    Hello Harshil,

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

    Regards,
    Nadezhda Petrova
    Telerik
     
    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
     
5 posts, 0 answered