Managing Media Libraries

Patryck Thomas asked on February 15, 2024 20:27

Hello, for some reason I'm not able to update the file name and location at the same time. Can you please provide an example of how to do so?

Here's my code:
public async UpdateMediaFile(MediaFileDto mediaData)
var mediaInfo = mediaFileInfoProvider.Get(mediaData.MediaFileId)
if (mediaInfo != null)
// Updates the media library file properties
mediaInfo.FileName = mediaData.FileName;
mediaInfo.FilePath = $"{mediaData.FilePath}/{mediaInfo.FileName}{mediaInfo.FileExtension}";
// Saves the media library file
mediaFileInfoProvider.Set(mediaInfo);

Also, how can I retrieve the list of folders in a Media Library and how can I check if a folder exists?

Thanks, Patryck Thomas

Recent Answers


Elmar Höfinghoff answered on February 20, 2024 11:10

MediaLibrary folders are file system folders. So you can use CMS.IO.Path which includes System.IO.Path to check if it exists. Which file system path is used is configured in the media library settings and the default path is ~/sitename/media/. The MediaFileInfo object contains only additional data for the file in the file system, like file title or description. If you want to move it, I would delete the old one and create a new one in the new location. If you want to keep some properties you can map it before doing this, e.g. "newFile.FileTitle = oldFile.FileTitle".

0 votesVote for this answer Mark as a Correct answer

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