I'm using Sitecore.Resources.Media.MediaCreatorOptions and Sitecore.Resources.Media.MediaCreator to programmatically create media items. I've set the MediaCreatorOptions.FileBased property to false yet the item created has the template /sitecore/templates/System/Media/Unversioned/File.

I assumed the item created would use the /sitecore/templates/System/Media/Unversioned/Image template.

Is there a way I can control the MediaCreator to create items with the Image template instead?

My code is executing from the uiUpload pipeline.

For reference, here is the code I'm using:

var mediaCreatorOptions = new MediaCreatorOptions
    Database = Sitecore.Configuration.Factory.GetDatabase("master"),
    Destination = item.Paths.Path + "/" + Path.GetFileNameWithoutExtension(mediaItem.MediaPath),
    IncludeExtensionInItemName = false,
    Language = Sitecore.Context.Language,
    Versioned = false,
    FileBased = false,
    AlternateText = Path.GetFileNameWithoutExtension(mediaItem.MediaPath),
    OverwriteExisting = false

var creator = new MediaCreator();
MediaItem newMediaItem;

using (new SecurityDisabler())
    newMediaItem = creator.CreateFromStream(stream, "test filename", mediaCreatorOptions);

2 Answers 2


The template used is dictated by the extension of the MediaCreatorOptions Destination. Look for the mediaLibrary\mediaTypes config section and you'll see how the template you get per extension is configured

<mediaType name="JPEG image" extensions="jpg, jpeg, jpe, jfif">

As your destination has no extension it is using the "*" setting

<mediaType name="Any" extensions="*">

You already have IncludeExtensionInItemName set to false so keep the extension in the Destination parameter so it knows what template to use.

  • Ah, yeah, that makes sense. I'm converting images to .webp in the uiUpload pipeline and hadn't added it as a mediaType yet. Thanks!
    – Iceape
    Dec 18, 2019 at 13:28

The creator.CreateFromStream selecting the template based on the fileName parameter. So you need add the extension to the fileName parameter like:

newMediaItem = creator.CreateFromStream(stream, "test filename.jpg", mediaCreatorOptions);
  • Thanks for pointing this out! The second parameter wasn't very clear to me what it did. It says it's "filePath" in one place and "fileName" in another.
    – Iceape
    Dec 18, 2019 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.