DevToys logo DevToys
  • Home
  • Blog
  • Documentation
  • Download
Search Results for

    Show / Hide Table of Contents

    Interface IFileStorage

    Provides a platform agnostic way to interact with the file system of the operating system the app is running on.

    Namespace: DevToys.Api
    Assembly: DevToys.Api.dll
    Syntax
    public interface IFileStorage

    Properties

    AppCacheDirectory

    Gets application's directory to store cache data. Cache data can be used for any data that needs to persist longer than temporary data, but shouldn't be data that is required to operate the app, as the operating system may clear this storage.

    Declaration
    string AppCacheDirectory { get; }
    Property Value
    Type Description
    string

    Methods

    CreateSelfDestroyingTempFile(string?)

    Creates a new temporary file in AppCacheDirectory that will be deleted when the app stops, or the next time is starts.

    Declaration
    FileInfo CreateSelfDestroyingTempFile(string? desiredFileExtension = null)
    Parameters
    Type Name Description
    string desiredFileExtension

    (optional) The extension the temporary file should use.

    Returns
    Type Description
    FileInfo

    Returns information to the file.

    FileExists(string)

    Determines whether the file indicated by the given relativeOrAbsoluteFilePath exists. If a relative path is indicated, use the AppCacheDirectory as working directory.

    Declaration
    bool FileExists(string relativeOrAbsoluteFilePath)
    Parameters
    Type Name Description
    string relativeOrAbsoluteFilePath

    The path to the file to check.

    Returns
    Type Description
    bool

    Returns true if the file exist

    OpenReadFile(string)

    Tries to open the given relativeOrAbsoluteFilePath with read access rights. If a relative path is indicated, use the AppCacheDirectory as working directory.

    Declaration
    FileStream OpenReadFile(string relativeOrAbsoluteFilePath)
    Parameters
    Type Name Description
    string relativeOrAbsoluteFilePath

    The path to the file to read.

    Returns
    Type Description
    FileStream

    Returns a read-only stream if the file exist and can be read, otherwise, raise an exception.

    OpenWriteFile(string, bool)

    Tries to open the given relativeOrAbsoluteFilePath with write access rights. The file will be created if it doesn't exist. If a relative path is indicated, use the AppCacheDirectory as working directory.

    Declaration
    FileStream OpenWriteFile(string relativeOrAbsoluteFilePath, bool replaceIfExist)
    Parameters
    Type Name Description
    string relativeOrAbsoluteFilePath

    The path to the file to write.

    bool replaceIfExist

    If true and that the file indicated by relativeOrAbsoluteFilePath already exist, overwrite it. Otherwise, open it without replacing it.

    Returns
    Type Description
    FileStream

    Returns a write-only stream.

    PickFolderAsync()

    Prompt the user to select a folder.

    Declaration
    ValueTask<string?> PickFolderAsync()
    Returns
    Type Description
    ValueTask<string>

    If succeeded, returns the absolute path to the folder the user selected, otherwise, returns null.

    PickOpenFileAsync(params string[])

    Prompt the user to select a file to open.

    Declaration
    ValueTask<SandboxedFileReader?> PickOpenFileAsync(params string[] fileTypes)
    Parameters
    Type Name Description
    string[] fileTypes

    The list of file types the user can choose. For example, ".txt". Use "*" for any file type.

    Returns
    Type Description
    ValueTask<SandboxedFileReader>

    If succeeded, returns a read-only stream corresponding to the file the user selected, otherwise, returns null.

    Remarks

    The returned items contain a stream. It won't be disposed automatically. It is important to dispose the stream yourself, when not needed anymore

    PickOpenFilesAsync(params string[])

    Prompt the user to select many files to open.

    Declaration
    ValueTask<SandboxedFileReader[]> PickOpenFilesAsync(params string[] fileTypes)
    Parameters
    Type Name Description
    string[] fileTypes

    The list of file types the user can choose. For example, ".txt". Use "*" for any file type.

    Returns
    Type Description
    ValueTask<SandboxedFileReader[]>

    If succeeded, returns a read-only stream corresponding to the file the user selected, otherwise, returns null.

    Remarks

    The returned items contain a stream. It won't be disposed automatically. It is important to dispose the stream yourself, when not needed anymore

    PickSaveFileAsync(params string[])

    Prompt the user to select a location to save a file, and decide of the file name.

    Declaration
    ValueTask<FileStream?> PickSaveFileAsync(params string[] fileTypes)
    Parameters
    Type Name Description
    string[] fileTypes

    The list of file types the user can choose. For example, ".txt". Use "*" for any file type.

    Returns
    Type Description
    ValueTask<FileStream>

    If succeeded, returns a write-only stream corresponding to the file the user selected, otherwise, returns null.

    Extension Methods

    LoggingExtensions.Log<T>(T)
    In this article
    DevToys logo © 2024 DevToys