Show / Hide Table of Contents

Class FileHelper

A helper class for File operations.

Inheritance
System.Object
FileHelper
Namespace: Volo.Abp.IO
Assembly: Volo.Abp.Core.dll
Syntax
public static class FileHelper : object

Methods

DeleteIfExists(String)

Checks and deletes given file if it does exists.

Declaration
public static bool DeleteIfExists(string filePath)
Parameters
Type Name Description
System.String filePath

Path of the file

Returns
Type Description
System.Boolean

GetExtension(String)

Gets extension of a file.

Declaration
public static string GetExtension(string fileNameWithExtension)
Parameters
Type Name Description
System.String fileNameWithExtension
Returns
Type Description
System.String

Returns extension without dot. Returns null if given fileNameWithExtension does not include dot.

ReadAllBytesAsync(String)

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

Declaration
public static Task<byte[]> ReadAllBytesAsync(string path)
Parameters
Type Name Description
System.String path

The file to open for reading.

Returns
Type Description
Task<System.Byte[]>

A string containing all lines of the file.

ReadAllLinesAsync(String, Encoding, FileMode, FileAccess, FileShare, Int32, FileOptions)

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

Declaration
public static Task<string[]> ReadAllLinesAsync(string path, Encoding encoding = null, FileMode fileMode = null, FileAccess fileAccess = null, FileShare fileShare = null, int bufferSize = 4096, FileOptions fileOptions = null)
Parameters
Type Name Description
System.String path

The file to open for reading.

Encoding encoding

Encoding of the file. Default is UTF8

FileMode fileMode

Specifies how the operating system should open a file. Default is Open

FileAccess fileAccess

Defines constants for read, write, or read/write access to a file. Default is Read

FileShare fileShare

Contains constants for controlling the kind of access other FileStream objects can have to the same file. Default is Read

System.Int32 bufferSize

Length of StreamReader buffer. Default is 4096.

FileOptions fileOptions

Indicates FileStream options. Default is Asynchronous (The file is to be used for asynchronous reading.) and SequentialScan (The file is to be accessed sequentially from beginning to end.)

Returns
Type Description
Task<System.String[]>

A string containing all lines of the file.

ReadAllTextAsync(String)

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

Declaration
public static Task<string> ReadAllTextAsync(string path)
Parameters
Type Name Description
System.String path

The file to open for reading.

Returns
Type Description
Task<System.String>

A string containing all lines of the file.

ReadFileWithoutBomAsync(String)

Opens a text file, reads content without BOM

Declaration
public static Task<string> ReadFileWithoutBomAsync(string path)
Parameters
Type Name Description
System.String path

The file to open for reading.

Returns
Type Description
Task<System.String>

A string containing all lines of the file.

Back to top Powered by Volosoft