Class File
- Namespace
- Kentico.Xperience.AzureStorage
- Assembly
- Kentico.Xperience.AzureStorage.dll
Implementation of File class for Azure.
public class File : AbstractFile
- Inheritance
-
objectFile
- Extension Methods
Constructors
File()
Initializes a new instance of the File class, which provides operations with files.
public File()
Methods
AppendAllText(string, string)
Opens a file, appends the specified string to the file, and then closes the file. If the file does not exist, this method creates a file, writes the specified string to the file, then closes the file.
public override void AppendAllText(string path, string contents)
Parameters
path
stringPath
contents
stringContent to write.
Exceptions
- ArgumentNullException
path
is null- ArgumentException
path
is empty or contains invalid characters- PathTooLongException
path
is too long
AppendAllText(string, string, Encoding)
Opens a file, appends the specified string to the file, and then closes the file. If the file does not exist, this method creates a file, writes the specified string to the file, then closes the file.
public override void AppendAllText(string path, string contents, Encoding encoding)
Parameters
path
stringPath
contents
stringContent to write.
encoding
EncodingThe character encoding to use
Exceptions
- ArgumentNullException
path
is null- ArgumentException
path
is empty or contains invalid characters- PathTooLongException
path
is too long
Copy(string, string)
Copies an existing file to a new file. Overwriting a file of the same name is not allowed.
public override void Copy(string sourceFileName, string destFileName)
Parameters
sourceFileName
stringPath to source file.
destFileName
stringPath to destination file.
Exceptions
- ArgumentNullException
sourceFileName
ordestFileName
is null- ArgumentException
sourceFileName
ordestFileName
is empty or contains invalid characters- PathTooLongException
sourceFileName
ordestFileName
is too long- FileNotFoundException
sourceFileName
does not exist- IOException
destFileName
already exists
Copy(string, string, bool)
Copies an existing file to a new file. Overwriting a file of the same name is allowed.
public override void Copy(string sourceFileName, string destFileName, bool overwrite)
Parameters
sourceFileName
stringPath to source file.
destFileName
stringPath to destination file.
overwrite
boolIf destination file should be overwritten.
Exceptions
- ArgumentNullException
sourceFileName
ordestFileName
is null- ArgumentException
sourceFileName
ordestFileName
is empty or contains invalid characters- PathTooLongException
sourceFileName
ordestFileName
is too long- FileNotFoundException
sourceFileName
does not exist- IOException
destFileName
already exists andoverwrite
is set to false
Create(string)
Creates or overwrites a file in the specified path.
public override FileStream Create(string path)
Parameters
path
stringPath to file.
Returns
Exceptions
- ArgumentNullException
path
is null- ArgumentException
path
is empty or contains invalid characters- PathTooLongException
path
is too long
CreateText(string)
Creates or overwrites a file for writing UTF-8 encoded text.
public override StreamWriter CreateText(string path)
Parameters
path
stringPath to file.
Returns
Exceptions
- ArgumentNullException
path
is null- ArgumentException
path
is empty or contains invalid characters- PathTooLongException
path
is too long
Delete(string)
Deletes the specified file. An exception is not thrown if the specified file does not exist.
public override void Delete(string path)
Parameters
path
stringPath to file
Exceptions
- ArgumentNullException
path
is null- ArgumentException
path
is empty or contains invalid characters- PathTooLongException
path
is too long
Exists(string)
Determines whether the specified file exists.
public override bool Exists(string path)
Parameters
path
stringPath to file.
Returns
- bool
GetFileUrl(string)
Returns URL to file. If can be accessed directly then direct URL is generated else URL with GetFile page is generated.
public override string GetFileUrl(string path)
Parameters
path
stringVirtual path starting with ~ or absolute path.
Returns
- string
GetLastWriteTime(string)
Returns the date and time the specified file or directory was last written to.
public override DateTime GetLastWriteTime(string path)
Parameters
path
stringPath to file.
Returns
- DateTime
Exceptions
- ArgumentNullException
path
is null- ArgumentException
path
is empty or contains invalid characters- PathTooLongException
path
is too long- FileNotFoundException
path
does not exist
Move(string, string)
Moves a specified file to a new location, providing the option to specify a new file name.
public override void Move(string sourceFileName, string destFileName)
Parameters
sourceFileName
stringSource file name.
destFileName
stringDestination file name.
Exceptions
- ArgumentNullException
sourceFileName
ordestFileName
is null- ArgumentException
sourceFileName
ordestFileName
is empty or contains invalid characters- PathTooLongException
sourceFileName
ordestFileName
is too long- FileNotFoundException
sourceFileName
does not exist- IOException
Both
sourceFileName
anddestFileName
lead to the same file
Open(string, FileMode, FileAccess)
Opens a FileStream on the specified path, with the specified mode and access.
public override FileStream Open(string path, FileMode mode, FileAccess access)
Parameters
path
stringPath to file.
mode
FileModeFile mode.
access
FileAccessFile access.
Returns
OpenRead(string)
Opens an existing file for reading.
public override FileStream OpenRead(string path)
Parameters
path
stringPath to file.
Returns
Exceptions
- ArgumentNullException
path
is null- ArgumentException
path
is empty or contains invalid characters- PathTooLongException
path
is too long- FileNotFoundException
path
does not exist
OpenText(string)
Opens an existing UTF-8 encoded text file for reading.
public override StreamReader OpenText(string path)
Parameters
path
stringPath to file
Returns
Exceptions
- ArgumentNullException
path
is null- ArgumentException
path
is empty or contains invalid characters- PathTooLongException
path
is too long- FileNotFoundException
path
does not exist
ReadAllBytes(string)
Opens a binary file, reads the contents of the file into a byte array, and then closes the file.
public override byte[] ReadAllBytes(string path)
Parameters
path
stringPath to file.
Returns
- byte[]
ReadAllText(string)
Opens a text file, reads all lines of the file, and then closes the file.
public override string ReadAllText(string path)
Parameters
path
stringPath to file.
Returns
- string
Exceptions
- ArgumentNullException
path
is null- ArgumentException
path
is empty or contains invalid characters- PathTooLongException
path
is too long- FileNotFoundException
path
does not exist
ReadAllText(string, Encoding)
Opens a text file, reads all lines of the file, and then closes the file.
public override string ReadAllText(string path, Encoding encoding)
Parameters
path
stringPath to file
encoding
EncodingThe character encoding to use
Returns
- string
Exceptions
- ArgumentNullException
path
is null- ArgumentException
path
is empty or contains invalid characters- PathTooLongException
path
is too long- FileNotFoundException
path
does not exist
SetAttributes(string, FileAttributes)
Sets the specified FileAttributes of the file on the specified path.
public override void SetAttributes(string path, FileAttributes fileAttributes)
Parameters
path
stringPath to file.
fileAttributes
FileAttributesFile attributes.
SetLastWriteTime(string, DateTime)
Sets the date and time that the specified file was last written to.
public override void SetLastWriteTime(string path, DateTime lastWriteTime)
Parameters
path
stringPath to file.
lastWriteTime
DateTimeLast write time.
Exceptions
- ArgumentNullException
path
is null- ArgumentException
path
is empty or contains invalid characters- PathTooLongException
path
is too long- FileNotFoundException
path
does not exist
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.
public override void WriteAllBytes(string path, byte[] bytes)
Parameters
path
stringPath to file.
bytes
byte[]Bytes to write.
Exceptions
- ArgumentNullException
path
is null- ArgumentException
path
is empty or contains invalid characters- PathTooLongException
path
is too long
WriteAllText(string, string)
Creates a new file, write the contents to the file, and then closes the file. If the target file already exists, it is overwritten.
public override void WriteAllText(string path, string contents)
Parameters
path
stringPath to file
contents
stringContent to write.
Exceptions
- ArgumentNullException
path
is null- ArgumentException
path
is empty or contains invalid characters- PathTooLongException
path
is too long
WriteAllText(string, string, Encoding)
Creates a new file, write the contents to the file, and then closes the file. If the target file already exists, it is overwritten.
public override void WriteAllText(string path, string contents, Encoding encoding)
Parameters
path
stringPath to file
contents
stringContent to write
encoding
EncodingThe character encoding to use
Exceptions
- ArgumentNullException
path
is null- ArgumentException
path
is empty or contains invalid characters- PathTooLongException
path
is too long