Class MediaLibraryHelper
- Namespace
- CMS.MediaLibrary
- Assembly
- CMS.MediaLibrary.dll
Class providing helper methods for media library.
[Obsolete("Media libraries and their APIs are obsolete and will be discontinued in the future. Please migrate all media library files to Content hub and use their corresponding content item APIs.", false)]
public class MediaLibraryHelper
- Inheritance
-
objectMediaLibraryHelper
- Extension Methods
Constructors
MediaLibraryHelper()
public MediaLibraryHelper()
Fields
OBJECT_TYPE_FOLDER
Object type for abstract media folder.
public const string OBJECT_TYPE_FOLDER = "media.folder"
Field Value
- string
Properties
SuffixRegex
Suffix regex for files and folders.
public static Regex SuffixRegex { get; set; }
Property Value
- Regex
Methods
CloneLibraryFiles(int, int, CloneSettings, CloneResult)
Clone media library files and folder to new media library.
public static void CloneLibraryFiles(int sourceLibraryID, int destinationLibraryID, CloneSettings cloneSettings, CloneResult cloneResult)
Parameters
sourceLibraryIDintSource library ID
destinationLibraryIDintDestination library ID
cloneSettingsCloneSettingsMediaLibrary clone settings. Only some parameters are used
cloneResultCloneResultResults of cloning will be stored to this instance
CopyRecursive(int, DirectoryInfo, string, string, int, string, bool, int)
Recursive copy media library directory.
public static void CopyRecursive(int libraryID, DirectoryInfo dir, string destinationDirectory, string sourcePath, int libraryPathIndex, string startingPoint, bool copyDB, int userId)
Parameters
libraryIDintLibrary ID
dirDirectoryInfoDirectory Info
destinationDirectorystringDestination path
sourcePathstringSource DB path
libraryPathIndexintLibrary path index
startingPointstringStarting point
copyDBboolIndicate if database entries should copy
userIdintID of the user performing action
CopyRecursive(int, int, DirectoryInfo, string, string, int, string, bool, int, bool, CloneSettings, CloneResult)
Recursive copy media library directory.
public static void CopyRecursive(int sourceLibraryID, int destinationLibraryID, DirectoryInfo dir, string destinationDirectory, string sourcePath, int libraryPathIndex, string startingPoint, bool copyDB, int userId, bool overwrite = false, CloneSettings cloneSettings = null, CloneResult cloneResult = null)
Parameters
sourceLibraryIDintSource library ID
destinationLibraryIDintDestination library ID
dirDirectoryInfoDirectory Info
destinationDirectorystringDestination path
sourcePathstringSource DB path
libraryPathIndexintLibrary path index
startingPointstringStarting point
copyDBboolIndicate if database entries should copy
userIdintID of the user performing action
overwriteboolIndicates if the destination folder and files can be overwritten
cloneSettingsCloneSettingsMediaLibrary clone settings. Only some parameters are used. If null, cloning is not used and FileMediaInfo is inserted as a directly.
cloneResultCloneResultResults of cloning will be stored to this instance
EnsurePhysicalPath(string)
Returns file path with slashes by DirectorySeparatorChar.
public static string EnsurePhysicalPath(string path)
Parameters
pathstringFile path
Returns
- string
EnsureUniqueDirectory(string)
Ensures unique path for the specified directory. If the directory with the specified name already exist in the target location new path with the added suffix is returned. The suffix consist of '_' sign and the number.
public static string EnsureUniqueDirectory(string path)
Parameters
pathstringDirectory path to ensure
Returns
- string
EnsureUniqueFileName(string)
Ensures unique path for the specified file. If the directory with the specified name already exist in the target location new path with the added suffix is returned. The suffix consist of '_' sign and the number.
public static string EnsureUniqueFileName(string path)
Parameters
pathstringComplete path to the file to ensure
Returns
- string
GetAllowedExtensions()
Returns allowed extensions list from settings.
public static string GetAllowedExtensions()
Returns
- string
GetDirectUrl(MediaFileInfo)
Returns a direct URL to the media file.
public static string GetDirectUrl(MediaFileInfo mediaFile)
Parameters
mediaFileMediaFileInfoMedia file for which the URL is generated.
Returns
- string
Remarks
Generates various URL types depending on the media library location:
| URL | Location |
|---|---|
| ~/mediaLibraryFolder/filename.extension | Media file is located in a local media library. |
| http://CDN/mediaLibraryFolder/filename.extension | Media file is located in a media library stored in CDN. |
| ~/getmedia/fileGUID/fileName.extension | Media file is located in a media library which is located outside of the CMS application. |
Exceptions
- ArgumentNullException
mediaFileis null.
GetMediaFileHiddenFolder()
Returns media file hidden folder name from settings.
public static string GetMediaFileHiddenFolder()
Returns
- string
GetMediaFilePreviewSuffix()
Returns media file preview suffix from settings.
public static string GetMediaFilePreviewSuffix()
Returns
- string
GetMediaRootFolderPath(string)
Returns physical path to the directory where all media libraries are stored. The returned path is within the CommonRootDirectoryName if configured.
public static string GetMediaRootFolderPath(string webFullPath = null)
Parameters
webFullPathstringPhysical path to the root of the web project (e.g. c:\WebProject), if it is not specified web application physical path is used
Returns
- string
- See Also
GetPermanentUrl(MediaFileInfo)
Returns a permanent URL to the media file.
public static string GetPermanentUrl(MediaFileInfo mediaFile)
Parameters
mediaFileMediaFileInfoMedia file which the URL will be generated for.
Returns
- string
Remarks
Generates various URL types depending on the media library location:
| URL | Location |
|---|---|
| ~/getmedia/fileGUID/fileName.extension | Media file is located in a media library. |
Exceptions
- ArgumentNullException
mediaFileis null.
GetPreviewFileName(string, string, string, string)
Returns media file preview file name.
public static string GetPreviewFileName(string fileName, string fileExtension, string previewExtension, string previewSuffix = null)
Parameters
fileNamestringFile name
fileExtensionstringFile extension
previewExtensionstringFile preview extension
previewSuffixstringPreview suffix
Returns
- string
GetPreviewFilePath(MediaFileInfo)
Returns media file preview file path.
public static string GetPreviewFilePath(MediaFileInfo fileInfo)
Parameters
fileInfoMediaFileInfoMedia file info
Returns
- string
HasPreview(int, string)
Returns true if file has preview file.
public static bool HasPreview(int libraryID, string filePath)
Parameters
libraryIDintLibrary ID
filePathstringFile path within library
Returns
- bool
IsExtensionAllowed(string)
Determines whether the file with the specified extension (case insensitive) can be uploaded into library module.
public static bool IsExtensionAllowed(string extension)
Parameters
extensionstringFile extension to check
Returns
- bool
IsExternalLibrary(string)
Returns true if media library root folder is outside of CMS.
public static bool IsExternalLibrary(string libraryFolder)
Parameters
libraryFolderstringLibrary folder.
Returns
- bool
MoveMediaFilePreview(MediaFileInfo, string)
Moves preview file into new location according new media file name.
public static void MoveMediaFilePreview(MediaFileInfo fileInfo, string newName)
Parameters
fileInfoMediaFileInfoMedia file info
newNamestringNew media file path
UpdateMediaFile(MediaLibraryInfo, MediaFileInfo, IUploadedFile)
Updates binary and related data of a media file specified by originalMediaFile.
public static MediaFileInfo UpdateMediaFile(MediaLibraryInfo library, MediaFileInfo originalMediaFile, IUploadedFile file)
Parameters
libraryMediaLibraryInfoLibrary of the media file to update.
originalMediaFileMediaFileInfoMedia file to update.
fileIUploadedFileFile to update the media file with.
Returns
Remarks
Creates and returns a clone of originalMediaFile with updated binary data
and related properties like FileSize, FileName, FileExtensions etc. The original binary file is deleted.
Exceptions
- ArgumentNullException
Thrown when
libraryororiginalMediaFileis null.