Importing a few gigs of images in hierarchical folders

paul krysiak asked on February 7, 2017 01:57

Hello Everyone
I need to import a bunch of media files into kentico. Are there instructions anywhere? I have found how to import and export them if they are in kentico but none for , choosing a media folder and uploading entire folder structures of media.

Any suggestions would be helpful, thanks

Correct Answer

Trevor Fayas answered on February 7, 2017 03:01

So you are just looking for a way to import files into the Media Center via API?

You have a couple of options.

  1. You can simply Place the folders and files into the Media Folder's physical location. The system will show them but say they have not been imported, which then you can import them (which makes a database 'record' of the physical file). This is fine if you have a smaller set of total folders, as you have to do it on each folder.

  2. You can import into the media library via API. One thing i've found in 8.2 (not sure if it's fixed in 9 or 10) that when you import into the media library, it 'recreates' the file during the processes, so you need to have a temporary location where the files will be placed, then import them into the final location into the media library. Below is that code:


string TemporaryFileFolder = "C:\\My\\Temporary\\Path\\";
string MediaLibaryPath = "C:\\inetpub\\websites\\MyKenticoSite\\CMS\\Media\\MyLibraryRootFolder";

// These change per file
string FileRelativePath = "SubDirectory1\\SubDirectory2\\";
string FileName = "MyFile.txt";
string CompletePath = TemporaryFileFolder+FileRelativePath+FileName;
string NewFileMediaFolderPath = CMS.IO.DirectoryHelper.CombinePath(MediaLibaryPath, FileRelativePath);
string NewMediaFileFullPath= NewFileMediaFolderPath + "\\" + FileName;

// Makes sure the parent folder is created in Kentico
CMS.IO.DirectoryHelper.EnsureDiskPath(NewFileMediaFolderPath ,MediaLibaryPath  );

// Creates the new Media File from the Temporary Path
var newFileInfo = new CMS.MediaLibrary.MediaFileInfo(CompletePath ,assetLibraryID);
// Sets the proper File path (relative link to the media library)
newFileInfo.FilePath = "/"+FileRelativePath.Replace("\\", "/") + FileName;

// Delete temporary file
0 votesVote for this answer Unmark Correct answer

Recent Answers

Roman Hutnyk answered on February 7, 2017 08:07

If you store media files in server's file system it should be as simple as copying files to ~/[sitename]/media/[library_folder]. Kentico will show those files in Media Library application, but with exclamation mark. You'll need to select all of them and hit import button, so Kentico saves files metadata into a database.

0 votesVote for this answer Mark as a Correct answer

paul krysiak answered on February 7, 2017 15:35

Thank you both for the help!
It is an export from Sharepoint I'll just do the manual thing. I can have other people help me with the meta data.

Thanks a bunch!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.