Search Results for

    Show / Hide Table of Contents
    View Source

    Class FileServiceBase<TRepository, TEntity>

    Provides base functionality for file-based services that manage file entities like scripts, stylesheets, and partial views.

    Inheritance
    object
    RepositoryService
    Namespace: Umbraco.Cms.Core.Services
    Assembly: Umbraco.Core.dll
    Syntax
    public abstract class FileServiceBase<TRepository, TEntity> : RepositoryService, IService, IBasicFileService<TEntity> where TRepository : IFileRepository, IReadRepository<string, TEntity> where TEntity : IFile
    Type Parameters
    Name Description
    TRepository

    The type of repository used for file operations.

    TEntity

    The type of file entity being managed.

    Remarks

    This abstract class provides common file operations including retrieval, content streaming, and validation for file-based entities stored in the file system.

    Constructors

    View Source

    FileServiceBase(ICoreScopeProvider, ILoggerFactory, IEventMessagesFactory, TRepository)

    Initializes a new instance of the FileServiceBase<TRepository, TEntity> class.

    Declaration
    public FileServiceBase(ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, TRepository repository)
    Parameters
    Type Name Description
    ICoreScopeProvider provider

    The core scope provider for database operations.

    ILoggerFactory loggerFactory

    The logger factory for creating loggers.

    IEventMessagesFactory eventMessagesFactory

    The factory for creating event messages.

    TRepository repository

    The repository for file data access.

    Properties

    View Source

    AllowedFileExtensions

    Gets the allowed file extensions for this file type.

    Declaration
    protected abstract string[] AllowedFileExtensions { get; }
    Property Value
    Type Description
    string[]
    View Source

    Repository

    Gets the repository used for file operations.

    Declaration
    public TRepository Repository { get; }
    Property Value
    Type Description
    TRepository

    Methods

    View Source

    GetAllAsync(params string[])

    Gets all TEntity by path, or all if no paths are specified.

    Declaration
    public Task<IEnumerable<TEntity>> GetAllAsync(params string[] paths)
    Parameters
    Type Name Description
    string[] paths

    Optional paths of TEntity to get.

    Returns
    Type Description
    Task<IEnumerable<TEntity>>

    IEnumerable of TEntity.

    View Source

    GetAsync(string)

    Gets TEntity by path.

    Declaration
    public Task<TEntity?> GetAsync(string path)
    Parameters
    Type Name Description
    string path

    The path to get TEntity from.

    Returns
    Type Description
    Task<TEntity>

    TEntity, or null if not found.

    View Source

    GetContentStreamAsync(string)

    Get the content of a file as a stream.

    Declaration
    public Task<Stream> GetContentStreamAsync(string path)
    Parameters
    Type Name Description
    string path

    The path to the file.

    Returns
    Type Description
    Task<Stream>

    A stream containing the contents of the file.

    View Source

    GetFileSizeAsync(string)

    Gets the size of a file in bytes.

    Declaration
    public Task<long> GetFileSizeAsync(string path)
    Parameters
    Type Name Description
    string path

    The path to the file.

    Returns
    Type Description
    Task<long>

    The file size in bytes.

    View Source

    HasValidFileExtension(string)

    Determines whether the specified file name has a valid file extension.

    Declaration
    protected virtual bool HasValidFileExtension(string fileName)
    Parameters
    Type Name Description
    string fileName

    The file name to validate.

    Returns
    Type Description
    bool

    true if the file extension is valid; otherwise, false.

    View Source

    HasValidFileName(string)

    Determines whether the specified file name is valid.

    Declaration
    protected virtual bool HasValidFileName(string fileName)
    Parameters
    Type Name Description
    string fileName

    The file name to validate.

    Returns
    Type Description
    bool

    true if the file name is valid; otherwise, false.

    View Source

    IsRootPath(string?)

    Checks if a path is considered a root path.

    Declaration
    protected virtual bool IsRootPath(string? path)
    Parameters
    Type Name Description
    string path

    The path to check.

    Returns
    Type Description
    bool

    true if the path is considered a root path; otherwise, false.

    Remarks

    We use "/" here instead of path separator because it's the virtual path used by backoffice, and not an actual file system path.

    View Source

    SetContentStreamAsync(string, Stream)

    Set the content of a file from a stream.

    Declaration
    public Task SetContentStreamAsync(string path, Stream content)
    Parameters
    Type Name Description
    string path

    The path to the file.

    Stream content

    The desired content of the file as a stream.

    Returns
    Type Description
    Task
    • View Source
    In this article
    Back to top Copyright © 2016-present Umbraco
    Generated by DocFX