Hello,
The SetMediaFileInfo should do the job:
private bool CreateMediaFile()
{
// Prepare the parameters
string filePath = "~/CMSAPIExamples/Code/Tools/MediaLibrary/Files/Powered_by_kentico2.gif";
// Get media library
MediaLibraryInfo library = MediaLibraryInfoProvider.GetMediaLibraryInfo("MyNewLibrary", SiteContext.CurrentSiteName);
if (library != null)
{
// Create new media file object
MediaFileInfo mediaFile = new MediaFileInfo(Server.MapPath(filePath), library.LibraryID);
// Create file info
FileInfo file = FileInfo.New(Server.MapPath(filePath));
if (file != null)
{
// Set the properties
mediaFile.FileName = "MyNewFile";
mediaFile.FileTitle = "My new file title";
mediaFile.FileDescription = "My new file description.";
mediaFile.FilePath = "MyNewFolder/MyNewFile.gif";
mediaFile.FileExtension = file.Extension;
mediaFile.FileMimeType = "image/gif";
mediaFile.FileSiteID = SiteContext.CurrentSiteID;
mediaFile.FileLibraryID = library.LibraryID;
mediaFile.FileSize = file.Length;
// Create the media file
MediaFileInfoProvider.SetMediaFileInfo(mediaFile);
return true;
}
}
return false;
}
Best Regards,
Jan Hermann