How to get field names
Hello,
I have a question about how to get field names. What I
need is to get a list of fileds for a DynamicContent given. When I call
DynamicContent. GetType().GetProperties() I get a list
of all properties names, but I need to get only those created by user. Could
you please tell me how to do this?
Example:
Users:
Name: John
Surname: Smith
Birth date: 01/01/1975
Address: 12, Commercial Road
Postal Code: 1111
City: London
Country: England
So, my question would be… How can I get a list of: “Name,
Surname, Birth date, address, Postal Code, City, Country”.
Thanks in advance.
Hello Javier,
Can you try this sample code?
DynamicModuleType dmType = null;
IQueryable<
DynamicModuleField
> dmFields = null;
var providers = ModuleBuilderManager.ProvidersCollection;
if (providers == null) providers = ModuleBuilderManager.GetManager().Providers;
foreach (var provider in providers)
dmType = provider.GetDynamicModuleTypes().Where(t => t.TypeName.Equals(sheet.Name)).First();
dmFields = provider.GetDynamicModuleFields().Where(f => f.FieldNamespace.Equals(dmType.GetFullTypeName()));
Hello Javier,
Just to clarify, any structure defined with the module builder is 100% defined by the user, so there are no default fields.
Regards,
Bilyana Ivanova
Telerik
Sorry, but this is not what I need to get. What I need is, given a Type, for example, "Telerik.Sitefinity.DynamicTypes.Model.Users", get its field names. In the example given in the first post, the result should be: "Name, Surname, Birth date, address, Postal Code, City, Country".
The reason why I am trying to do this, is that I need to get dynamically fields and values of a given type in order to get data, for example, of users, providers, clients... From my database.
Hello Javier,
With the sample code that I provided if you have a dynamic content type called Store with these fields: Title, Phone, UserID, StoreImage, Address (see content_type.png), then executing this code
DynamicModuleType dmType = null;
IQueryable<
DynamicModuleField
> dmFields = null;
var providers = ModuleBuilderManager.ProvidersCollection;
if (providers == null) providers = ModuleBuilderManager.GetManager().Providers;
foreach (var provider in providers)
dmType = provider.GetDynamicModuleTypes().Where(t => t.TypeName.Equals("Store")).First();
dmFields = provider.GetDynamicModuleFields().Where(f => f.FieldNamespace.Equals(dmType.GetFullTypeName()));
will return Title, Phone, UserID, StoreImage, Address (see dmFields.png. Isn't this what you wanted to achieve?
Regards,
Bilyana Ivanova
Telerik
Yes!! You are right, sorry. It works!!!
I also got it with this code:
MetadataManager metadataManager = MetadataManager.GetManager();
MetaType contentMetaType = metadataManager.GetMetaType(type);
return contentMetaType.Fields;
Thank you very much for your help.