There are many multimedia types in Administration folder in Tridion. I want to write a method that returns the tcm id for a given mime type, e.g. for gif mime type it should return "tcm:0-1-65544".
Can anyone have an idea over this?
Each schema has a property called AllowedMultimediaTypes which returns a list, and the Default Multimedia Schema is usually set up to allow all the types. If it doesn't allow all the types, then you can create a special schema for this purpose.
So all you have to do is get the AllowedMultimediaTypes of the Default Multimedia Schema (or your special schema allowing all the types) and then match your inputted mime type to the mimetimes of each MultimediaType returned.
Here is some sample off the top (not tested):
Schema defaultMMSchema = (Schema)engine.GetObject("Your-Default-MMSchema-WebDav-Path");
IList<MultimediaType> mmTypes = defaultMMSchema.AllowedMultimediaTypes;
foreach(MultimediaType mt in mmTypes)
{
switch(mt.MimeType)
{
case "jpg":
...
}
}
Alternatively, the TCM IDs of the out-of-the-box Multimedia types are constant, so you don't need to worry about them changing after Content Porting to another environment. Therefore you can write a class that provides a mapping of mime type to tcm ID. Note: this will not be as elegant if you create custom item types since you'll need to update your code with it's TCM ID per each Tridion environment.
You can just get a list of all multimedia types and then select the one you need:
var mmType = ClientAdmin.GetSystemWideList(new MultimediaTypesFilterData()).Single(mt => ((MultimediaTypeData)mt).MimeType == "image/jpeg");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With