Class File
Represents an abstract file which provides basic functionality for a File with an Alias and Name
Namespace: Umbraco.Cms.Core.Models
Assembly: Umbraco.Core.dll
Syntax
[DataContract(IsReference = true)]
public abstract class File : EntityBase, IFile, IEntity, IDeepCloneable, IRememberBeingDirty, ICanBeDirty
Constructors
View SourceFile(string, Func<File, string?>?)
Initializes a new instance of the File class with the specified path.
Declaration
protected File(string path, Func<File, string?>? getFileContent = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | The path to the file. |
| Func<File, string> | getFileContent | An optional function to lazily load file content. |
Properties
View SourceAlias
Gets or sets the Alias of the File, which is the name without the extension
Declaration
[DataMember]
public virtual string Alias { get; }
Property Value
| Type | Description |
|---|---|
| string |
Content
Gets or sets the Content of a File
Declaration
[DataMember]
[DoNotClone]
public virtual string? Content { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Remarks
Marked as DoNotClone, because it should be lazy-reloaded from disk.
GetFileContent
Gets or sets the function used to lazily load file content.
Declaration
public Func<File, string?>? GetFileContent { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<File, string> |
Name
Gets or sets the Name of the File including extension
Declaration
[DataMember]
public virtual string Name { get; }
Property Value
| Type | Description |
|---|---|
| string |
OriginalPath
Gets the original path of the file
Declaration
public string OriginalPath { get; }
Property Value
| Type | Description |
|---|---|
| string |
Path
Gets or sets the Path to the File from the root of the file's associated IFileSystem
Declaration
[DataMember]
public virtual string Path { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
VirtualPath
Gets or sets the file's virtual path (i.e. the file path relative to the root of the website)
Declaration
public string? VirtualPath { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
View SourceDeepCloneNameAndAlias(File)
Performs deep cloning of the name and alias properties.
Declaration
protected virtual void DeepCloneNameAndAlias(File clone)
Parameters
| Type | Name | Description |
|---|---|---|
| File | clone | The cloned file instance. |
Remarks
This exists so that classes that manage name and alias differently, e.g. Template, can implement their own cloning.
PerformDeepClone(object)
Used by inheritors to modify the DeepCloning logic
Declaration
protected override void PerformDeepClone(object clone)
Parameters
| Type | Name | Description |
|---|---|---|
| object | clone |
ResetOriginalPath()
Called to re-set the OriginalPath to the Path
Declaration
public void ResetOriginalPath()