Show / Hide Table of Contents

Interface IFile

Provides methods for working with file.

Namespace: Terrasoft.IO
Assembly: Terrasoft.IO.dll
Syntax
public interface IFile

Methods

Copy(String, String)

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

Declaration
void Copy(string sourceFileName, string destinationFileName)
Parameters
Type Name Description
System.String sourceFileName

The file to copy.

System.String destinationFileName

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

Exceptions
Type Condition
System.UnauthorizedAccessException

The caller does not have the required permission.

System.ArgumentNullException

sourceFileName or destinationFileName is null.

System.ArgumentException

sourceFileName or destinationFileName is a zero-length string, contains only white space, or contains invalid characters as defined in System.IO.Path.GetInvalidPathChars.

System.IO.DirectoryNotFoundException

The path specified in sourceFileName or destinationFileName is invalid, (for example, it is on an unmapped drive).

System.IO.FileNotFoundException

File specified in sourceFileName was not found.

System.IO.IOException

destinationFileName exists.

-or-

An I/O error has occurred.

System.NotSupportedException

sourceFileName or destinationFileName is in an invalid format.

Copy(String, String, Boolean)

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

Declaration
void Copy(string sourceFileName, string destFileName, bool overwrite)
Parameters
Type Name Description
System.String sourceFileName

The file to copy.

System.String destFileName

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

System.Boolean overwrite

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

Exceptions
Type Condition
System.UnauthorizedAccessException

The caller does not have the required permission.

-or-

destFileName is read-only.

System.ArgumentException

sourceFileName or destFileName is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.GetInvalidPathChars.

-or-

sourceFileName or destFileName specifies a directory.

System.ArgumentNullException

sourceFileName or destFileName is null.

System.IO.PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.IO.DirectoryNotFoundException

The path specified in sourceFileName or destFileName is invalid (for example, it is on an unmapped drive).

System.IO.FileNotFoundException

sourceFileName was not found.

System.IO.IOException

destFileName exists and overwrite is false.

-or-

An I/O error has occurred.

System.NotSupportedException

sourceFileName or destFileName is in an invalid format.

Create(String)

Creates or overwrites a file that can be used for asynchronous reading and writing in the specified path.

Declaration
Stream Create(string path)
Parameters
Type Name Description
System.String path

The path and name of the file to create.

Returns
Type Description
System.IO.Stream

A System.IO.Stream that provides read/write access to the specified path.

Exceptions
Type Condition
System.UnauthorizedAccessException

The caller does not have the required permission.

-or-

path specified a file that is read-only.

System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by System.IO.Path.GetInvalidPathChars.

System.ArgumentNullException

path is null.

Delete(String)

Deletes specified file.

Declaration
void Delete(string path)
Parameters
Type Name Description
System.String path

Name of file to be deleted. Wildcard characters are not supported.

Exceptions
Type Condition
System.ArgumentException

path is empty, contains only white space or contains one or more invalid characters as defined by System.IO.Path.GetInvalidPathChars.

System.ArgumentNullException

path is null.

System.IO.DirectoryNotFoundException

Specified path is invalid (for example, it is on an unmapped drive).

System.IO.IOException

Specified file is in use.

System.NotSupportedException

path path is in an invalid format.

System.UnauthorizedAccessException

Caller does not have required permission.

-or-

path is directory.

-or-

File is an executable file that is in use.

-or-

path specifies read-only file.

Exists(String)

Determines whether specified file exists.

Declaration
bool Exists(string path)
Parameters
Type Name Description
System.String path

File to check.

Returns
Type Description
System.Boolean

True if caller has required permissions and path contains name of an existing file. Otherwise returns false. Also returns false when path is null, contains wrong value or zero-length string. If caller does not have sufficient permissions to read specified file, no exception is thrown and method returns false regardless of path existence.

GetAttributes(String)

Gets the System.IO.FileAttributes of the file on the path.

Declaration
FileAttributes GetAttributes(string path)
Parameters
Type Name Description
System.String path

The path to the file.

Returns
Type Description
System.IO.FileAttributes

The System.IO.FileAttributes of the file on the path.

Exceptions
Type Condition
System.ArgumentException

path is empty, contains only white spaces, or contains invalid characters.

System.IO.PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.NotSupportedException

path is in an invalid format.

System.IO.FileNotFoundException

path represents a file and is invalid, such as being on an unmapped drive, or the file cannot be found.

System.IO.DirectoryNotFoundException

path represents a directory and is invalid, such as being on an unmapped drive, or the directory cannot be found.

System.IO.IOException

This file is being used by another process.

System.UnauthorizedAccessException

The caller does not have the required permission.

Move(String, String)

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

Declaration
void Move(string sourceFileName, string destFileName)
Parameters
Type Name Description
System.String sourceFileName

The name of the file to move. Can include a relative or absolute path.

System.String destFileName

The new path and name for the file.

Exceptions
Type Condition
System.IO.IOException

The destination file already exists.

-or-

sourceFileName was not found.

System.ArgumentNullException

sourceFileName or destFileName is null.

System.ArgumentException

sourceFileName or destFileName is a zero-length string, contains only white space, or contains invalid characters as defined in Path.GetInvalidPathChars.

System.UnauthorizedAccessException

The caller does not have the required permission.

System.IO.PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.IO.DirectoryNotFoundException

The path specified in sourceFileName or destFileName is invalid, (for example, it is on an unmapped drive).

System.NotSupportedException

sourceFileName or destFileName is in an invalid format.

Open(String, FileMode)

Opens a System.IO.FileStream on the specified path with read/write access.

Declaration
Stream Open(string path, FileMode mode)
Parameters
Type Name Description
System.String path

The file to open.

System.IO.FileMode mode

A System.IO.FileMode value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.

Returns
Type Description
System.IO.Stream

A System.IO.Stream opened in the specified mode and path, with read/write access and not shared.

Exceptions
Type Condition
System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.GetInvalidPathChars.

System.ArgumentNullException

path is null.

System.IO.PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.IO.DirectoryNotFoundException

The specified path is invalid, (for example, it is on an unmapped drive).

System.IO.IOException

An I/O error occurred while opening the file.

System.UnauthorizedAccessException

path specified a file that is read-only.-or- This operation is not supported on the current platform.-or- path specified a directory.-or- The caller does not have the required permission. -or- mode is System.IO.FileMode.Create and the specified file is a hidden file.

System.ArgumentOutOfRangeException

mode specified an invalid value.

System.IO.FileNotFoundException

The file specified in path was not found.

System.NotSupportedException

path is in an invalid format.

OpenRead(String)

Opens an existing file for reading.

Declaration
Stream OpenRead(string path)
Parameters
Type Name Description
System.String path

The file to be opened for reading.

Returns
Type Description
System.IO.Stream

A read-only System.IO.Stream on the specified path.

Exceptions
Type Condition
System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by System.IO.Path.GetInvalidPathChars.

System.ArgumentNullException

path is null.

System.IO.DirectoryNotFoundException

The specified path is invalid.

System.UnauthorizedAccessException

path specified a directory, or the caller does not have the required permission.

System.IO.FileNotFoundException

The file specified in path was not found.

System.NotSupportedException

path is in an invalid format.

System.IO.IOException

An I/O error occurred while opening the file.

ReadAllBytes(String)

Opens a binary file, reads contents of file into a byte array, and then closes file.

Declaration
byte[] ReadAllBytes(string path)
Parameters
Type Name Description
System.String path

File to open for reading.

Returns
Type Description
System.Byte[]

A byte array containing data of file.

Exceptions
Type Condition
System.ArgumentException

path is empty, contains only white space or contains one or more invalid characters as defined by System.IO.Path.GetInvalidPathChars.

System.ArgumentNullException

path is null.

System.IO.DirectoryNotFoundException

Specified path is invalid (for example, it is on an unmapped drive).

System.IO.IOException

An I/O error occurred while opening file.

System.IO.FileNotFoundException

File specified in path was not found.

System.NotSupportedException

path path is in an invalid format.

System.Security.SecurityException

Caller does not have required permission.

System.UnauthorizedAccessException

This operation is not supported on current platform.

-or-

path contains path to directory.

-or-

Caller does not have required permission.

ReadAllLines(String)

Opens a text file, reads all lines of the file, and then closes the file.

Declaration
IEnumerable<string> ReadAllLines(string path)
Parameters
Type Name Description
System.String path

The file to read from.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.String>

A string enumeration containing all lines of the file.

Exceptions
Type Condition
System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters defined by the System.IO.Path.GetInvalidPathChars method.

System.ArgumentNullException

Either path is null.

System.IO.DirectoryNotFoundException

path is invalid (for example, it is on an unmapped drive).

System.IO.IOException

An I/O error occurred while opening the file.

System.UnauthorizedAccessException

path specifies a file that is read-only.

-or-

This operation is not supported on the current platform.

-or-

path is a directory.

-or-

The caller does not have the required permission.

System.IO.FileNotFoundException

File specified in path was not found.

System.NotSupportedException

path is in an invalid format.

System.Security.SecurityException

The caller does not have the required permission.

ReadAllText(String)

Opens a text file, reads all lines of the file, and then closes the file.

Declaration
string ReadAllText(string path)
Parameters
Type Name Description
System.String path

The file to open for reading.

Returns
Type Description
System.String

A string containing all lines of the file.

Exceptions
Type Condition
System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.GetInvalidPathChars.

System.ArgumentNullException

path is null.

System.IO.PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.IO.DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

System.IO.IOException

An I/O error occurred while opening the file.

System.UnauthorizedAccessException

path specified a file that is read-only. -or- This operation is not supported on the current platform. -or- path specified a directory. -or- The caller does not have the required permission.

System.IO.FileNotFoundException

The file specified in path was not found.

System.NotSupportedException

path is in an invalid format.

System.Security.SecurityException

The caller does not have the required permission.

ReadAllText(String, Encoding)

Opens a file, reads all lines of the file with the specified encoding, and then closes the file.

Declaration
string ReadAllText(string path, Encoding encoding)
Parameters
Type Name Description
System.String path

The file to open for reading.

System.Text.Encoding encoding

The encoding applied to the contents of the file.

Returns
Type Description
System.String

A string containing all lines of the file.

Exceptions
Type Condition
System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.GetInvalidPathChars.

System.ArgumentNullException

path is null.

System.IO.PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.IO.DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

System.IO.IOException

An I/O error occurred while opening the file.

System.UnauthorizedAccessException

path specified a file that is read-only.-or- This operation is not supported on the current platform.-or- path specified a directory.-or- The caller does not have the required permission.

System.IO.FileNotFoundException

The file specified in path was not found.

System.NotSupportedException

path is in an invalid format.

System.Security.SecurityException

The caller does not have the required permission.

SetAttributes(String, FileAttributes)

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

Declaration
void SetAttributes(string path, FileAttributes fileAttributes)
Parameters
Type Name Description
System.String path

The path to the file.

System.IO.FileAttributes fileAttributes

A bitwise combination of the enumeration values.

Exceptions
Type Condition
System.ArgumentException

path is empty, contains only white spaces, contains invalid characters, or the file attribute is invalid.

System.IO.PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.NotSupportedException

path is in an invalid format.

System.IO.DirectoryNotFoundException

The specified path is invalid, (for example, it is on an unmapped drive).

System.IO.FileNotFoundException

The file cannot be found.

System.UnauthorizedAccessException

path specified a file that is read-only.-or- This operation is not supported on the current platform.-or- path specified a directory.-or- The caller does not have the required permission.

SetCreationTime(String, DateTime)

Sets the date and time the file was created.

Declaration
void SetCreationTime(string path, DateTime creationTime)
Parameters
Type Name Description
System.String path

The file for which to set the creation date and time information.

System.DateTime creationTime

A System.DateTime containing the value to set for the creation date and time of path. This value is expressed in local time.

Exceptions
Type Condition
System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars.

System.ArgumentNullException

path is null.

System.IO.PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.IO.IOException

An I/O error occurred while performing the operation.

System.ArgumentOutOfRangeException

creationTime specifies a value outside the range of dates, times, or both permitted for this operation.

System.UnauthorizedAccessException

The caller does not have the required permission.

System.NotSupportedException

path is in an invalid format.

SetLastWriteTimeUtc(String, DateTime)

Sets the date and time, in coordinated universal time (UTC), that the specified file was last written to.

Declaration
void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)
Parameters
Type Name Description
System.String path

The file for which to set the date and time information.

System.DateTime lastWriteTimeUtc

A DateTime containing the value to set for the last write date and time of path. This value is expressed in UTC time.

WriteAllBytes(String, Byte[])

Creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is overwritten.

Declaration
void WriteAllBytes(string path, byte[] bytes)
Parameters
Type Name Description
System.String path

The file to write to.

System.Byte[] bytes

The bytes to write to the file.

Exceptions
Type Condition
System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.GetInvalidPathChars.

System.ArgumentNullException

path is null or the byte array is empty.

System.IO.PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.IO.DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

System.IO.IOException

An I/O error occurred while opening the file.

System.UnauthorizedAccessException

path specified a file that is read-only.

-or-

This operation is not supported on the current platform.

-or-

path specified a directory.

-or-

The caller does not have the required permission.

System.NotSupportedException

path is in an invalid format.

System.Security.SecurityException

The caller does not have the required permission.

WriteAllLines(String, IEnumerable<String>)

Creates a new file, writes a collection of strings contents to the file, and then closes the file.

Declaration
void WriteAllLines(string path, IEnumerable<string> contents)
Parameters
Type Name Description
System.String path

The file to write to.

System.Collections.Generic.IEnumerable<System.String> contents

The lines to write to the file.

Exceptions
Type Condition
System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters defined by the System.IO.Path.GetInvalidPathChars method.

System.ArgumentNullException

Either path or contents is null.

System.IO.DirectoryNotFoundException

path is invalid (for example, it is on an unmapped drive).

System.IO.IOException

An I/O error occurred while opening the file.

System.NotSupportedException

path is in an invalid format.

System.Security.SecurityException

The caller does not have the required permission.

System.UnauthorizedAccessException

path specifies a file that is read-only.

-or-

This operation is not supported on the current platform.

-or-

path is a directory.

-or-

The caller does not have the required permission.

WriteAllText(String, String)

Creates a new file, writes the specified string to the file, and then closes the file. If the target file already exists, it is overwritten.

Declaration
void WriteAllText(string path, string contents)
Parameters
Type Name Description
System.String path

The file to write to.

System.String contents

The string to write to the file.

Exceptions
Type Condition
System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.GetInvalidPathChars.

System.ArgumentNullException

path is null or contents is empty.

System.IO.PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.IO.DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

System.IO.IOException

An I/O error occurred while opening the file.

System.UnauthorizedAccessException

path specified a file that is read-only.-or- This operation is not supported on the current platform.-or- path specified a directory.-or- The caller does not have the required permission.

System.NotSupportedException

path is in an invalid format.

System.Security.SecurityException

The caller does not have the required permission.

WriteAllText(String, String, Encoding)

Creates a new file, writes the specified string to the file, and then closes the file. If the target file already exists, it is overwritten.

Declaration
void WriteAllText(string path, string contents, Encoding encoding)
Parameters
Type Name Description
System.String path

The file to write to.

System.String contents

The string to write to the file.

System.Text.Encoding encoding

The encoding to apply to the string.

Exceptions
Type Condition
System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters as defined by Path.GetInvalidPathChars.

System.ArgumentNullException

path is null or contents is empty.

System.IO.PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters.

System.IO.DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

System.IO.IOException

An I/O error occurred while opening the file.

System.UnauthorizedAccessException

path specified a file that is read-only.-or- This operation is not supported on the current platform.-or- path specified a directory.-or- The caller does not have the required permission.

System.NotSupportedException

path is in an invalid format.

System.Security.SecurityException

The caller does not have the required permission.

Extension Methods

ReflectionUtilities.GetPropertyValue(Object, String)
ReflectionUtilities.GetPropertyDefValue(Object, String, Object)
ReflectionUtilities.TryGetPropertyValue(Object, String, out Object)
ReflectionUtilities.HasProperty(Object, String)
ReflectionUtilities.GetPropertyValue(Object, String, BindingFlags)
ReflectionUtilities.GetPropertyValueByPath(Object, String)
ReflectionUtilities.SetPropertyValue(Object, String, Object)
ReflectionUtilities.TrySetPropertyValue(Object, String, Object)
ValidateUtilities.CheckArgumentNull(Object, String)
ValidateUtilities.CheckDependencyNull(Object, String)
ValidateUtilities.EnsureDependencyNotNull<T>(T, String)
MetaDataTestUtils.MetaPropertiesShouldNotHaveDefValue<TInstance>(TInstance)
MetaDataTestUtils.MetaPropertiesShouldNotHaveDefValue<TInstance>(TInstance, Boolean)
NSubstituteExtension.Protected(Object, String, Object[])
NSubstituteExtension.Protected(Object, String, Boolean, Object[])
NSubstituteExtension.ProtectedGeneric<T>(Object, String, Object[])
NSubstituteExtension.ProtectedGeneric<T>(Object, String, Boolean, Object[])
NSubstituteExtension.ProtectedProperty(Object, String)
NSubstituteExtension.MatchInstance<T>(T)
SubstituteUtilities.GetIsSubstituteObject(Object)
SubstituteUtilities.Instead<TInstance, TValue>(TInstance, Func<TInstance, TValue>)
Back to top Generated by DocFX