Get media files

Vote:
 

How do I get a media file with IContentRepository(and is that the way I suppose to do it)?

 

I have uploaded an image to a folder and using it in a block. Then I tried to get the AlternativeText property of my ImageFile and it is null even though the file is published with set values. 


var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
var contentLink = new ContentReference(id);
var media = contentRepository.GetDefault<ImageFile>(contentLink);

 

All media propertys are null..

#80601
Jan 27, 2014 17:13
Vote:
 

Use Get<ImageFile>(contentLink) instead of GetDefault. GetDefault is used for creating new items.




#80602
Jan 27, 2014 17:44
Vote:
 

Awsome! Right in front of my nose :)

#80605
Jan 27, 2014 18:57
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.