So you are just looking for a way to import files into the Media Center via API?
You have a couple of options.
-
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.
-
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;
newFileInfo.Insert();
// Delete temporary file
System.IO.File.Delete(CompletePath);