Add custom field to List - Programmatically
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
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.
Thanks.
Hi Venkata,
If I have created some custom fields in List Itmes then can I access them using fluent API?
Regards,
Harshil Shukla
Hello Harshil,
The following article shows how you can access custom fields: Getting the value of a custom field.
Regards,
Nadezhda Petrova
Telerik