Class PhysicalFileSystem
Inheritance
Namespace: Umbraco.Cms.Core.IO
Assembly: Umbraco.Core.dll
Syntax
public class PhysicalFileSystem : IPhysicalFileSystem, IFileSystem, IFileProviderFactory
  Constructors
View SourcePhysicalFileSystem(IIOHelper, IHostingEnvironment, ILogger<PhysicalFileSystem>, String, String)
Declaration
public PhysicalFileSystem(IIOHelper ioHelper, IHostingEnvironment hostingEnvironment, ILogger<PhysicalFileSystem> logger, string rootPath, string rootUrl)
  Parameters
| Type | Name | Description | 
|---|---|---|
| IIOHelper | ioHelper | |
| IHostingEnvironment | hostingEnvironment | |
| ILogger<PhysicalFileSystem> | logger | |
| System.String | rootPath | |
| System.String | rootUrl | 
Properties
View SourceCanAddPhysical
Declaration
public bool CanAddPhysical { get; }
  Property Value
| Type | Description | 
|---|---|
| System.Boolean | 
Methods
View SourceAddFile(String, Stream)
Saves a file.
Declaration
public void AddFile(string path, Stream stream)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path of the file.  | 
      
| Stream | stream | A stream containing the file data.  | 
      
Remarks
Overrides the existing file, if any.
AddFile(String, Stream, Boolean)
Saves a file.
Declaration
public void AddFile(string path, Stream stream, bool overrideExisting)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path of the file.  | 
      
| Stream | stream | A stream containing the file data.  | 
      
| System.Boolean | overrideExisting | A value indicating whether to override the existing file, if any.  | 
      
Remarks
If a file exists and overrideExisting is false, an exception is thrown.
AddFile(String, String, Boolean, Boolean)
Declaration
public void AddFile(string path, string physicalPath, bool overrideIfExists = true, bool copy = false)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | |
| System.String | physicalPath | |
| System.Boolean | overrideIfExists | |
| System.Boolean | copy | 
Create()
Declaration
public IFileProvider Create()
  Returns
| Type | Description | 
|---|---|
| IFileProvider | 
DeleteDirectory(String)
Deletes a directory.
Declaration
public void DeleteDirectory(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path of the directory.  | 
      
DeleteDirectory(String, Boolean)
Deletes a directory.
Declaration
public void DeleteDirectory(string path, bool recursive)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path of the directory.  | 
      
| System.Boolean | recursive | A value indicating whether to recursively delete sub-directories.  | 
      
DeleteFile(String)
Deletes a file.
Declaration
public void DeleteFile(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path to the file.  | 
      
DirectoryExists(String)
Gets a value indicating whether a directory exists.
Declaration
public bool DirectoryExists(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path of the directory.  | 
      
Returns
| Type | Description | 
|---|---|
| System.Boolean | A value indicating whether a directory exists.  | 
      
EnsureDirectory(String)
Declaration
protected virtual void EnsureDirectory(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | 
EnsureDirectorySeparatorChar(String)
Declaration
protected string EnsureDirectorySeparatorChar(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | 
Returns
| Type | Description | 
|---|---|
| System.String | 
EnsureTrailingSeparator(String)
Declaration
protected string EnsureTrailingSeparator(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | 
Returns
| Type | Description | 
|---|---|
| System.String | 
EnsureUrlSeparatorChar(String)
Declaration
protected string EnsureUrlSeparatorChar(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | 
Returns
| Type | Description | 
|---|---|
| System.String | 
FileExists(String)
Gets a value indicating whether a file exists.
Declaration
public bool FileExists(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path to the file.  | 
      
Returns
| Type | Description | 
|---|---|
| System.Boolean | A value indicating whether the file exists.  | 
      
GetCreated(String)
Gets the created date of a directory or file.
Declaration
public DateTimeOffset GetCreated(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path to the directory or the file.  | 
      
Returns
| Type | Description | 
|---|---|
| DateTimeOffset | The created date of the directory or the file.  | 
      
GetDirectories(String)
Gets directories in a directory.
Declaration
public IEnumerable<string> GetDirectories(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path to the directory.  | 
      
Returns
| Type | Description | 
|---|---|
| IEnumerable<System.String> | The filesystem-relative path to the directories in the directory.  | 
      
Remarks
Filesystem-relative paths use forward-slashes as directory separators.
GetFiles(String)
Gets files in a directory.
Declaration
public IEnumerable<string> GetFiles(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path of the directory.  | 
      
Returns
| Type | Description | 
|---|---|
| IEnumerable<System.String> | The filesystem-relative path to the files in the directory.  | 
      
Remarks
Filesystem-relative paths use forward-slashes as directory separators.
GetFiles(String, String)
Gets files in a directory.
Declaration
public IEnumerable<string> GetFiles(string path, string filter)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path of the directory.  | 
      
| System.String | filter | A filter.  | 
      
Returns
| Type | Description | 
|---|---|
| IEnumerable<System.String> | The filesystem-relative path to the matching files in the directory.  | 
      
Remarks
Filesystem-relative paths use forward-slashes as directory separators.
GetFullPath(String)
Gets the full path.
Declaration
public string GetFullPath(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The full or filesystem-relative path.  | 
      
Returns
| Type | Description | 
|---|---|
| System.String | The full path.  | 
      
Remarks
On the physical filesystem, the full path is the rooted (ie non-relative), safe (ie within this filesystem's root) path. All separators are Path.DirectorySeparatorChar.
GetLastModified(String)
Gets the last-modified date of a directory or file.
Declaration
public DateTimeOffset GetLastModified(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path to the directory or the file.  | 
      
Returns
| Type | Description | 
|---|---|
| DateTimeOffset | The last modified date of the directory or the file.  | 
      
GetRelativePath(String)
Gets the filesystem-relative path of a full path or of an URL.
Declaration
public string GetRelativePath(string fullPathOrUrl)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | fullPathOrUrl | The full path or URL.  | 
      
Returns
| Type | Description | 
|---|---|
| System.String | The path, relative to this filesystem's root.  | 
      
Remarks
The relative path is relative to this filesystem's root, not starting with any directory separator. All separators are forward-slashes.
GetSize(String)
Gets the size of a file.
Declaration
public long GetSize(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path to the file.  | 
      
Returns
| Type | Description | 
|---|---|
| System.Int64 | The file of the size, in bytes.  | 
      
Remarks
If the file does not exist, returns -1.
GetUrl(String)
Gets the URL.
Declaration
public string GetUrl(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path.  | 
      
Returns
| Type | Description | 
|---|---|
| System.String | The URL.  | 
      
Remarks
All separators are forward-slashes.
OpenFile(String)
Opens a file.
Declaration
public Stream OpenFile(string path)
  Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | path | The filesystem-relative path to the file.  | 
      
Returns
| Type | Description | 
|---|---|
| Stream | 
WithRetry(Action)
Declaration
protected void WithRetry(Action action)
  Parameters
| Type | Name | Description | 
|---|---|---|
| Action | action |