Class FileSystemExtensions
Provides extension methods for file system operations.
Inheritance
Namespace: Umbraco.Extensions
Assembly: Umbraco.Core.dll
Syntax
public static class FileSystemExtensions
Methods
View SourceCopyFile(IFileSystem, string, string)
Copies a file from one path to another within the file system.
Declaration
public static void CopyFile(this IFileSystem fs, string path, string newPath)
Parameters
| Type | Name | Description |
|---|---|---|
| IFileSystem | fs | The file system. |
| string | path | The source file path. |
| string | newPath | The destination file path. |
CreateFolder(IFileSystem, string)
Creates a folder at the specified path.
Declaration
public static void CreateFolder(this IFileSystem fs, string folderPath)
Parameters
| Type | Name | Description |
|---|---|---|
| IFileSystem | fs | The file system. |
| string | folderPath | The folder path to create. |
GetExtension(IFileSystem, string)
Gets the file extension from a path.
Declaration
public static string GetExtension(this IFileSystem fs, string path)
Parameters
| Type | Name | Description |
|---|---|---|
| IFileSystem | fs | The file system. |
| string | path | The file path. |
Returns
| Type | Description |
|---|---|
| string | The file extension including the period. |
GetFileName(IFileSystem, string)
Gets the file name from a path.
Declaration
public static string GetFileName(this IFileSystem fs, string path)
Parameters
| Type | Name | Description |
|---|---|---|
| IFileSystem | fs | The file system. |
| string | path | The file path. |
Returns
| Type | Description |
|---|---|
| string | The file name including extension. |
GetStreamHash(Stream)
Computes the SHA1 hash of a stream.
Declaration
public static string GetStreamHash(this Stream fileStream)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | fileStream | The stream to hash. |
Returns
| Type | Description |
|---|---|
| string | The hexadecimal string representation of the hash. |
OpenReadWithRetry(FileInfo, int, int)
Attempts to open the file at
filePath up to maxRetries times,
with a thread sleep time of sleepPerRetryInMilliseconds between retries.
Declaration
public static FileStream OpenReadWithRetry(this FileInfo file, int maxRetries = 5, int sleepPerRetryInMilliseconds = 50)
Parameters
| Type | Name | Description |
|---|---|---|
| FileInfo | file | |
| int | maxRetries | |
| int | sleepPerRetryInMilliseconds |
Returns
| Type | Description |
|---|---|
| FileStream |
TryCreateFileProvider(IFileSystem, out IFileProvider)
Creates a new Microsoft.Extensions.FileProviders.IFileProvider from the file system.
Declaration
public static bool TryCreateFileProvider(this IFileSystem fileSystem, out IFileProvider fileProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| IFileSystem | fileSystem | The file system. |
| IFileProvider | fileProvider | When this method returns, contains an Microsoft.Extensions.FileProviders.IFileProvider created from the file system. |
Returns
| Type | Description |
|---|---|
| bool |
|