Search Results for

    Show / Hide Table of Contents

    Class File

    Class for creating FileStream objects, and some basic file management routines such as Delete, etc.

    Inheritance
    object
    File
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: System.IO
    Assembly: System.IO.FileSystem.dll
    Syntax
    public static class File

    Methods

    Copy(string, string, bool)

    Copies an existing file to a new file. Overwriting a file of the same name is allowed.

    Declaration
    public static void Copy(string sourceFileName, string destFileName, bool overwrite)
    Parameters
    Type Name Description
    string sourceFileName

    The file to copy.

    string destFileName

    The name of the destination file. This cannot be a directory.

    bool overwrite

    true if the destination file can be overwritten; otherwise, false.

    Exceptions
    Type Condition
    ArgumentException

    sourceFileName or destFileName is null or empty

    Copy(string, string)

    Copies an existing file to a new file. Overwriting a file of the same name is not allowed.

    Declaration
    public static void Copy(string sourceFileName, string destFileName)
    Parameters
    Type Name Description
    string sourceFileName

    The file to copy.

    string destFileName

    The name of the destination file. This cannot be a directory or an existing file.

    Exceptions
    Type Condition
    ArgumentException

    sourceFileName or destFileName is null or empty

    Create(string)

    Creates or overwrites a file in the specified path.

    Declaration
    public static FileStream Create(string path)
    Parameters
    Type Name Description
    string path

    The path and name of the file to create.

    Returns
    Type Description
    FileStream

    Delete(string)

    Deletes the specified file.

    Declaration
    public static void Delete(string path)
    Parameters
    Type Name Description
    string path

    The name of the file to be deleted. Wild-card characters are not supported.

    Exceptions
    Type Condition
    ArgumentNullException

    Path must be defined.

    IOException

    Directory not found. or Not allowed to delete ReadOnly Files. or Not allowed to delete Directories.

    Exists(string)

    Determines whether the specified file exists.

    Declaration
    public static bool Exists(string path)
    Parameters
    Type Name Description
    string path

    The file to check.

    Returns
    Type Description
    bool

    GetAttributes(string)

    Gets the FileAttributes of the file on the path.

    Declaration
    public static FileAttributes GetAttributes(string path)
    Parameters
    Type Name Description
    string path

    The path to the file.

    Returns
    Type Description
    FileAttributes

    The FileAttributes of the file on the path.

    Exceptions
    Type Condition
    IOException

    File not found.

    GetLastWriteTime(string)

    Determines the time of the last write/modification to file under given path.

    Declaration
    public static DateTime GetLastWriteTime(string path)
    Parameters
    Type Name Description
    string path
    Returns
    Type Description
    DateTime

    Time of the last write/modification.

    Exceptions
    Type Condition
    IOException

    Logical drive or a file under given path does not exist.

    Move(string, string)

    Moves a specified file to a new location, providing the option to specify a new file name.

    Declaration
    public static void Move(string sourceFileName, string destFileName)
    Parameters
    Type Name Description
    string sourceFileName

    The name of the file to move. Absolute path.

    string destFileName

    The new path and name for the file.

    Exceptions
    Type Condition
    Exception

    Source File not existing or Destination File already existing.

    SetAttributes(string, FileAttributes)

    Sets the specified FileAttributes of the file on the specified path.

    Declaration
    public static void SetAttributes(string path, FileAttributes fileAttributes)
    Parameters
    Type Name Description
    string path

    The path to the file.

    FileAttributes fileAttributes

    A bitwise combination of the enumeration values.

    In This Article
    Back to top Copyright © 2023 nanoFramework Contributors
    Generated by DocFX