How to programmatically get all content item types?
I would like to be able to write code that can fetch all the content item types in my Sitefinity app. For example, I'd like to get a list of the types Event, News, GenericContent, etc (every type that's listed under Content > Types of Content in the administrative view). Is that possible?
My alternative is to hard-code the types. That may be okay if it's impossible to fetch them dynamically.
Hi,
At this moment there are no way to do this. The modules are in no way dependable to each other. We are in progress of creating an API to get all types of content in Sitefinity, but at this point it is internal - mabe it will be oppened in some of the next releases.
I think that the only solution for now is to hardcode the content types.
Regards,
Bonny
Telerik
Hi Bonny,
I am usingSitefinity 8.0 right now. Is it possible to get list of content types with Sitefinity 8.0?
Thanks
Atit
Hi Atit,
You can get the types through the MetadataManager. Here is a sample code for your reference:
var manager = MetadataManager.GetManager();
var types = manager.GetMetaTypes();
List<
string
> allTypes =
new
List<
string
>();
foreach
(var type
in
types)
string
fullTypeName = type.FullTypeName;
allTypes.Add(fullTypeName);