Yes we have:
var fileInfo = new FileInfo(file.FileName); var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>(); var contentMediaResolver = ServiceLocator.Current.GetInstance<ContentMediaResolver>(); ContentType correctMediaType = contentTypeRepository.Load(contentMediaResolver.GetFirstMatching(fileInfo.Extension));
After that you just do:
var newFile = ServiceLocator.Current.GetInstance<IContentRepository>().GetDefault<IContentMedia>(dest.Directory.ContentLink, correctMediaType.ID);
Hope that help!
I have an upload function where you can upload file to a ContentFolder.
The code looks something like this:
GenericMedia is a base class for media files and then i have a few specialized media types (ImageFile, VideoFile etc) with extra properties.
Instead of always creating generic media i would like to create the correct media type based on the media descriptor attribute in my media types.
Does EPiServer have a function for retrieving the correct media type based on the file extention? Im guessiong something simular is done when uploading a file in edit mode.