Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get tcm id of a multimedia type say jpg from Tridion through Core Service?

Tags:

tridion

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?

like image 310
Aquarius24 Avatar asked May 07 '12 05:05

Aquarius24


2 Answers

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.

like image 71
Nickoli Roussakov Avatar answered Sep 28 '22 03:09

Nickoli Roussakov


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");
like image 42
Andrey Marchuk Avatar answered Sep 28 '22 02:09

Andrey Marchuk