Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Importing Images into the Media Library using code View modes: 
User avatar
Member
Member
david-ripteq.com - 7/27/2010 10:04:32 PM
   
Importing Images into the Media Library using code
Hi All,

We manage many of the image assets externally to Kentico, and have developed a mechanism to export particular images to a Dropbox folder in a Kentico Media library using FTP. This process is a bit clunky, as a user then has to go into the Media Library, and manually 'import' the image.

Is there a better way to programmatically 'send an image' to the media library?

Cheers,
David.

User avatar
Kentico Support
Kentico Support
kentico_radekm - 8/9/2010 4:34:47 AM
   
RE:Importing Images into the Media Library using code
Hello.

Yes, it is possible to do it via API. You will need to write common ASP.NET script to load content of your media library´s folder and use our API to import it into database.

First, you will need to create MediaFileInfo object (in CMS.MediaLibrary class) and fill all required properties (fileName, filePath, fileExtension, etc.). Then you need to import it via ImportMediaFileInfo(MediaFileInfo) method, which import media file into database. The method is in CMS.MediaLibrary.MediaFileInfoProvider class. You can do it in cycle, so for every item in your folder, you will create appropriate object and import it. You can see more details about mentioned methods in our API reference file.

Best Regards,
Radek Macalik

User avatar
Member
Member
smorschhauser-sedonatek - 8/16/2010 2:11:16 PM
   
RE:Importing Images into the Media Library using code
I tried this and was successful in adding the image information to the database... but the image STILL shows up in the MediaLibrary as needing to be imported. The Media_File information is in the database, but the image in the MediaLibrary has an "!" instead of the icon to select the image.

User avatar
Kentico Support
Kentico Support
kentico_radekm - 8/27/2010 3:03:59 AM
   
RE:Importing Images into the Media Library using code
Hello.

It seems that maybe some property of MediaFileInfo object has not been set properly (maybe filePath). Could you please send appropriate code in e-mail to support@kentico.com, so we can investigate it? Please refer to this forum post. Thank you.

Best Regards,
Radek Macalik