Interface IMediaService
Defines the Media Service, which is an easy access to operations involving IMedia
Namespace: Umbraco.Core.Services
Assembly: Umbraco.Core.dll
Syntax
public interface IMediaService : IContentServiceBase, IService
Methods
View SourceCount(String)
Declaration
int Count(string mediaTypeAlias = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | mediaTypeAlias |
Returns
Type | Description |
---|---|
System.Int32 |
CountChildren(Int32, String)
Declaration
int CountChildren(int parentId, string mediaTypeAlias = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | parentId | |
System.String | mediaTypeAlias |
Returns
Type | Description |
---|---|
System.Int32 |
CountDescendants(Int32, String)
Declaration
int CountDescendants(int parentId, string mediaTypeAlias = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | parentId | |
System.String | mediaTypeAlias |
Returns
Type | Description |
---|---|
System.Int32 |
CountNotTrashed(String)
Declaration
int CountNotTrashed(string contentTypeAlias = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | contentTypeAlias |
Returns
Type | Description |
---|---|
System.Int32 |
CreateMedia(String, Guid, String, Int32)
Creates an IMedia object using the alias of the IMediaType that this Media should based on.
Declaration
IMedia CreateMedia(string name, Guid parentId, string mediaTypeAlias, int userId = -1)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the Media object |
System.Guid | parentId | Id of Parent for the new Media item |
System.String | mediaTypeAlias | Alias of the IMediaType |
System.Int32 | userId | Optional id of the user creating the media item |
Returns
Type | Description |
---|---|
IMedia | IMedia |
Remarks
Note that using this method will simply return a new IMedia without any identity as it has not yet been persisted. It is intended as a shortcut to creating new media objects that does not invoke a save operation against the database.
CreateMedia(String, Int32, String, Int32)
Creates an IMedia object using the alias of the IMediaType that this Media should based on.
Declaration
IMedia CreateMedia(string name, int parentId, string mediaTypeAlias, int userId = -1)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the Media object |
System.Int32 | parentId | Id of Parent for the new Media item |
System.String | mediaTypeAlias | Alias of the IMediaType |
System.Int32 | userId | Optional id of the user creating the media item |
Returns
Type | Description |
---|---|
IMedia | IMedia |
Remarks
Note that using this method will simply return a new IMedia without any identity as it has not yet been persisted. It is intended as a shortcut to creating new media objects that does not invoke a save operation against the database.
CreateMedia(String, IMedia, String, Int32)
Creates an IMedia object using the alias of the IMediaType that this Media should based on.
Declaration
IMedia CreateMedia(string name, IMedia parent, string mediaTypeAlias, int userId = -1)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the Media object |
IMedia | parent | Parent IMedia for the new Media item |
System.String | mediaTypeAlias | Alias of the IMediaType |
System.Int32 | userId | Optional id of the user creating the media item |
Returns
Type | Description |
---|---|
IMedia | IMedia |
Remarks
Note that using this method will simply return a new IMedia without any identity as it has not yet been persisted. It is intended as a shortcut to creating new media objects that does not invoke a save operation against the database.
CreateMediaWithIdentity(String, Int32, String, Int32)
Creates an IMedia object using the alias of the IMediaType that this Media should based on.
Declaration
IMedia CreateMediaWithIdentity(string name, int parentId, string mediaTypeAlias, int userId = -1)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the Media object |
System.Int32 | parentId | Id of Parent for the new Media item |
System.String | mediaTypeAlias | Alias of the IMediaType |
System.Int32 | userId | Optional id of the user creating the media item |
Returns
Type | Description |
---|---|
IMedia | IMedia |
Remarks
This method returns an IMedia object that has been persisted to the database and therefor has an identity.
CreateMediaWithIdentity(String, IMedia, String, Int32)
Creates an IMedia object using the alias of the IMediaType that this Media should based on.
Declaration
IMedia CreateMediaWithIdentity(string name, IMedia parent, string mediaTypeAlias, int userId = -1)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of the Media object |
IMedia | parent | Parent IMedia for the new Media item |
System.String | mediaTypeAlias | Alias of the IMediaType |
System.Int32 | userId | Optional id of the user creating the media item |
Returns
Type | Description |
---|---|
IMedia | IMedia |
Remarks
This method returns an IMedia object that has been persisted to the database and therefor has an identity.
Delete(IMedia, Int32)
Permanently deletes an IMedia object
Declaration
Attempt<OperationResult> Delete(IMedia media, int userId = -1)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | The IMedia to delete |
System.Int32 | userId | Id of the User deleting the Media |
Returns
Type | Description |
---|---|
Attempt<OperationResult> |
Remarks
Please note that this method will completely remove the Media from the database, but current not from the file system.
DeleteMediaFile(String)
Deletes a media file.
Declaration
void DeleteMediaFile(string filepath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filepath | The filesystem path to the media. |
DeleteMediaOfType(Int32, Int32)
Deletes all media of specified type. All children of deleted media is moved to Recycle Bin.
Declaration
void DeleteMediaOfType(int mediaTypeId, int userId = -1)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | mediaTypeId | Id of the IMediaType |
System.Int32 | userId | Optional Id of the user deleting Media |
Remarks
This needs extra care and attention as its potentially a dangerous and extensive operation
DeleteMediaOfTypes(IEnumerable<Int32>, Int32)
Deletes all media of the specified types. All Descendants of deleted media that is not of these types is moved to Recycle Bin.
Declaration
void DeleteMediaOfTypes(IEnumerable<int> mediaTypeIds, int userId = -1)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Int32> | mediaTypeIds | Ids of the IMediaTypes |
System.Int32 | userId | Optional Id of the user issuing the delete operation |
Remarks
This needs extra care and attention as its potentially a dangerous and extensive operation
DeleteVersion(Int32, Int32, Boolean, Int32)
Permanently deletes specific version(s) from an IMedia object.
Declaration
void DeleteVersion(int id, int versionId, bool deletePriorVersions, int userId = -1)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | Id of the IMedia object to delete a version from |
System.Int32 | versionId | Id of the version to delete |
System.Boolean | deletePriorVersions | Boolean indicating whether to delete versions prior to the versionId |
System.Int32 | userId | Optional Id of the User deleting versions of a Content object |
DeleteVersions(Int32, DateTime, Int32)
Permanently deletes versions from an IMedia object prior to a specific date.
Declaration
void DeleteVersions(int id, DateTime versionDate, int userId = -1)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | Id of the IMedia object to delete versions from |
System.DateTime | versionDate | Latest version date |
System.Int32 | userId | Optional Id of the User deleting versions of a Content object |
EmptyRecycleBin()
Empties the Recycle Bin by deleting all IMedia that resides in the bin
Declaration
[Obsolete("Use EmptyRecycleBin with explicit indication of user ID instead")]
OperationResult EmptyRecycleBin()
Returns
Type | Description |
---|---|
OperationResult |
EmptyRecycleBin(Int32)
Empties the Recycle Bin by deleting all IMedia that resides in the bin
Declaration
OperationResult EmptyRecycleBin(int userId = -1)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | userId | Optional Id of the User emptying the Recycle Bin |
Returns
Type | Description |
---|---|
OperationResult |
GetAncestors(Int32)
Gets a collection of IMedia objects, which are ancestors of the current media.
Declaration
IEnumerable<IMedia> GetAncestors(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | Id of the IMedia to retrieve ancestors for |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> | An Enumerable list of IMedia objects |
GetAncestors(IMedia)
Gets a collection of IMedia objects, which are ancestors of the current media.
Declaration
IEnumerable<IMedia> GetAncestors(IMedia media)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | IMedia to retrieve ancestors for |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> | An Enumerable list of IMedia objects |
GetById(Guid)
Gets an IMedia object by its 'UniqueId'
Declaration
IMedia GetById(Guid key)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | key | Guid key of the Media to retrieve |
Returns
Type | Description |
---|---|
IMedia | IMedia |
GetById(Int32)
Gets an IMedia object by Id
Declaration
IMedia GetById(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | Id of the Content to retrieve |
Returns
Type | Description |
---|---|
IMedia | IMedia |
GetByIds(IEnumerable<Guid>)
Declaration
IEnumerable<IMedia> GetByIds(IEnumerable<Guid> ids)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Guid> | ids |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> |
GetByIds(IEnumerable<Int32>)
Declaration
IEnumerable<IMedia> GetByIds(IEnumerable<int> ids)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Int32> | ids |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> |
GetByLevel(Int32)
Gets a collection of IMedia objects by Level
Declaration
IEnumerable<IMedia> GetByLevel(int level)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | level | The level to retrieve Media from |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> | An Enumerable list of IMedia objects |
GetMediaByPath(String)
Gets an IMedia object from the path stored in the 'umbracoFile' property.
Declaration
IMedia GetMediaByPath(string mediaPath)
Parameters
Type | Name | Description |
---|---|---|
System.String | mediaPath | Path of the media item to retrieve (for example: /media/1024/koala_403x328.jpg) |
Returns
Type | Description |
---|---|
IMedia | IMedia |
GetMediaFileContentStream(String)
Gets the content of a media as a stream.
Declaration
Stream GetMediaFileContentStream(string filepath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filepath | The filesystem path to the media. |
Returns
Type | Description |
---|---|
System.IO.Stream | The content of the media. |
GetMediaFileSize(String)
Gets the size of a media.
Declaration
long GetMediaFileSize(string filepath)
Parameters
Type | Name | Description |
---|---|---|
System.String | filepath | The filesystem path to the media. |
Returns
Type | Description |
---|---|
System.Int64 | The size of the media. |
GetPagedChildren(Int32, Int64, Int32, out Int64, IQuery<IMedia>, Ordering)
Gets a collection of IMedia objects by Parent Id
Declaration
IEnumerable<IMedia> GetPagedChildren(int id, long pageIndex, int pageSize, out long totalRecords, IQuery<IMedia> filter = null, Ordering ordering = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | Id of the Parent to retrieve Children from |
System.Int64 | pageIndex | Page number |
System.Int32 | pageSize | Page size |
System.Int64 | totalRecords | Total records query would return without paging |
IQuery<IMedia> | filter | |
Ordering | ordering |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> | An Enumerable list of IContent objects |
GetPagedDescendants(Int32, Int64, Int32, out Int64, IQuery<IMedia>, Ordering)
Gets a collection of IMedia objects by Parent Id
Declaration
IEnumerable<IMedia> GetPagedDescendants(int id, long pageIndex, int pageSize, out long totalRecords, IQuery<IMedia> filter = null, Ordering ordering = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | Id of the Parent to retrieve Descendants from |
System.Int64 | pageIndex | Page number |
System.Int32 | pageSize | Page size |
System.Int64 | totalRecords | Total records query would return without paging |
IQuery<IMedia> | filter | |
Ordering | ordering |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> | An Enumerable list of IContent objects |
GetPagedMediaInRecycleBin(Int64, Int32, out Int64, IQuery<IMedia>, Ordering)
Gets a collection of an IMedia objects, which resides in the Recycle Bin
Declaration
IEnumerable<IMedia> GetPagedMediaInRecycleBin(long pageIndex, int pageSize, out long totalRecords, IQuery<IMedia> filter = null, Ordering ordering = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int64 | pageIndex | |
System.Int32 | pageSize | |
System.Int64 | totalRecords | |
IQuery<IMedia> | filter | |
Ordering | ordering |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> | An Enumerable list of IMedia objects |
GetPagedOfType(Int32, Int64, Int32, out Int64, IQuery<IMedia>, Ordering)
Gets paged documents of a content
Declaration
IEnumerable<IMedia> GetPagedOfType(int contentTypeId, long pageIndex, int pageSize, out long totalRecords, IQuery<IMedia> filter = null, Ordering ordering = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | contentTypeId | The page number. |
System.Int64 | pageIndex | The page number. |
System.Int32 | pageSize | The page size. |
System.Int64 | totalRecords | Total number of documents. |
IQuery<IMedia> | filter | Search text filter. |
Ordering | ordering | Ordering infos. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> |
GetPagedOfTypes(Int32[], Int64, Int32, out Int64, IQuery<IMedia>, Ordering)
Gets paged documents for specified content types
Declaration
IEnumerable<IMedia> GetPagedOfTypes(int[] contentTypeIds, long pageIndex, int pageSize, out long totalRecords, IQuery<IMedia> filter = null, Ordering ordering = null)
Parameters
Type | Name | Description |
---|---|---|
System.Int32[] | contentTypeIds | The page number. |
System.Int64 | pageIndex | The page number. |
System.Int32 | pageSize | The page size. |
System.Int64 | totalRecords | Total number of documents. |
IQuery<IMedia> | filter | Search text filter. |
Ordering | ordering | Ordering infos. |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> |
GetParent(Int32)
Gets the parent of the current media as an IMedia item.
Declaration
IMedia GetParent(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | Id of the IMedia to retrieve the parent from |
Returns
Type | Description |
---|---|
IMedia | Parent IMedia object |
GetParent(IMedia)
Gets the parent of the current media as an IMedia item.
Declaration
IMedia GetParent(IMedia media)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | IMedia to retrieve the parent from |
Returns
Type | Description |
---|---|
IMedia | Parent IMedia object |
GetRootMedia()
Gets a collection of IMedia objects, which reside at the first level / root
Declaration
IEnumerable<IMedia> GetRootMedia()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> | An Enumerable list of IMedia objects |
GetVersion(Int32)
Gets a specific version of an IMedia item.
Declaration
IMedia GetVersion(int versionId)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | versionId | Id of the version to retrieve |
Returns
Type | Description |
---|---|
IMedia | An IMedia item |
GetVersions(Int32)
Gets a collection of an IMedia objects versions by Id
Declaration
IEnumerable<IMedia> GetVersions(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IMedia> | An Enumerable list of IMedia objects |
HasChildren(Int32)
Checks whether an IMedia item has any children
Declaration
bool HasChildren(int id)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | id | Id of the IMedia |
Returns
Type | Description |
---|---|
System.Boolean | True if the media has any children otherwise False |
Move(IMedia, Int32, Int32)
Moves an IMedia object to a new location
Declaration
Attempt<OperationResult> Move(IMedia media, int parentId, int userId = -1)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | The IMedia to move |
System.Int32 | parentId | Id of the Media's new Parent |
System.Int32 | userId | Id of the User moving the Media |
Returns
Type | Description |
---|---|
Attempt<OperationResult> | True if moving succeeded, otherwise False |
MoveToRecycleBin(IMedia, Int32)
Deletes an IMedia object by moving it to the Recycle Bin
Declaration
Attempt<OperationResult> MoveToRecycleBin(IMedia media, int userId = -1)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | The IMedia to delete |
System.Int32 | userId | Id of the User deleting the Media |
Returns
Type | Description |
---|---|
Attempt<OperationResult> |
RecycleBinSmells()
Returns true if there is any media in the recycle bin
Declaration
bool RecycleBinSmells()
Returns
Type | Description |
---|---|
System.Boolean |
Save(IEnumerable<IMedia>, Int32, Boolean)
Saves a collection of IMedia objects
Declaration
Attempt<OperationResult> Save(IEnumerable<IMedia> medias, int userId = -1, bool raiseEvents = true)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<IMedia> | medias | Collection of IMedia to save |
System.Int32 | userId | Id of the User saving the Media |
System.Boolean | raiseEvents | Optional boolean indicating whether or not to raise events. |
Returns
Type | Description |
---|---|
Attempt<OperationResult> |
Save(IMedia, Int32, Boolean)
Saves a single IMedia object
Declaration
Attempt<OperationResult> Save(IMedia media, int userId = -1, bool raiseEvents = true)
Parameters
Type | Name | Description |
---|---|---|
IMedia | media | The IMedia to save |
System.Int32 | userId | Id of the User saving the Media |
System.Boolean | raiseEvents | Optional boolean indicating whether or not to raise events. |
Returns
Type | Description |
---|---|
Attempt<OperationResult> |
SetMediaFileContent(String, Stream)
Sets the content of a media.
Declaration
void SetMediaFileContent(string filepath, Stream content)
Parameters
Type | Name | Description |
---|---|---|
System.String | filepath | The filesystem path to the media. |
System.IO.Stream | content | The content of the media. |
Sort(IEnumerable<IMedia>, Int32, Boolean)
Sorts a collection of IMedia objects by updating the SortOrder according to the ordering of items in the passed in System.Collections.Generic.IEnumerable<T>.
Declaration
bool Sort(IEnumerable<IMedia> items, int userId = -1, bool raiseEvents = true)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<IMedia> | items | |
System.Int32 | userId | |
System.Boolean | raiseEvents |
Returns
Type | Description |
---|---|
System.Boolean | True if sorting succeeded, otherwise False |