Try our conversational search powered by Generative AI!

Class NativeFile

Implements UnifiedFile for a truly native (local physically available) file. Obtained through VirtualPathNativeProvider.GetFile()

Inheritance
System.Object
NativeFile
Inherited Members
Namespace: EPiServer.Web.Hosting
Assembly: EPiServer.dll
Version: 8.11.0
Syntax
public class NativeFile : UnifiedFile

Constructors

NativeFile(UnifiedDirectory, VirtualPathUnifiedProvider, String, String, Boolean)

Initializes a new instance of the NativeFile class.

Declaration
public NativeFile(UnifiedDirectory directory, VirtualPathUnifiedProvider provider, string virtualPath, string localPath, bool bypassAccessCheck)
Parameters
Type Name Description
UnifiedDirectory directory

The parent directory of the file. Only used by UnifiedFile for ACL checks on page folders for unsaved pages.

VirtualPathUnifiedProvider provider

The provider hosting this file.

System.String virtualPath

The virtual path of the file.

System.String localPath

The local file system path.

System.Boolean bypassAccessCheck

if set to true access checks are bypassed for operations on the file. Access checks in the underlying file system are still performed.

Fields

fileInfo

Reference to the underlying file.

Declaration
protected FileInfo fileInfo
Field Value
Type Description
System.IO.FileInfo

Properties

Changed

Gets the date and time when the file last was written to.

Declaration
public override DateTime Changed { get; }
Property Value
Type Description
System.DateTime
Overrides

Created

Gets the date and time when the file was created.

Declaration
public override DateTime Created { get; }
Property Value
Type Description
System.DateTime
Overrides

Extension

Gets the file extension, for example '.doc'.

Declaration
public override string Extension { get; }
Property Value
Type Description
System.String
Overrides

Length

The size of the file (in bytes).

Declaration
public override long Length { get; }
Property Value
Type Description
System.Int64
Overrides

LocalPath

Gets the local file system path of the file.

Declaration
public override string LocalPath { get; }
Property Value
Type Description
System.String
Overrides

Name

Gets the display name of the file.

Declaration
public override string Name { get; }
Property Value
Type Description
System.String

Parent

Parent UnifiedDirectory of the current UnifiedFile.

Declaration
public override UnifiedDirectory Parent { get; }
Property Value
Type Description
UnifiedDirectory
Overrides
Remarks

When Parent property is overriden: if PageForAclCheck is set, SetPageForAccessControl on parent should be called with PageForAclCheck as parameter before parent is returned.

PermanentLinkVirtualPath

Gets the permanent link virtual path. Not supported by this implementation.

Declaration
public override string PermanentLinkVirtualPath { get; }
Property Value
Type Description
System.String
Overrides
Remarks

Permanent links are not supported by the NativeFile implementation.

Summary

Gets the summary. The summary for NativeFile is a inmemory summary meaning it will not be persisted.

Declaration
public override IUnifiedSummary Summary { get; }
Property Value
Type Description
IUnifiedSummary

The summary.

Overrides

Methods

CopyTo(String)

Creates a copy of this file instance at the specified virtual path.

Declaration
public override void CopyTo(string destVirtualPath)
Parameters
Type Name Description
System.String destVirtualPath

The destination virtual path.

Overrides
Remarks

When copying the file to another NativeDirectory the underlying file system copy functionality is used, otherwise the file stream is copied to the destination provider.

CopyTo(String, Guid)

Creates a copy of this file instance at the specified virtual path.

Declaration
public override void CopyTo(string newVirtualPath, Guid fileId)
Parameters
Type Name Description
System.String newVirtualPath

The full virtual path to copy the file to, including the file name.

System.Guid fileId

The guid for the file. (Ignored in this implementation)

Overrides
Remarks

This method simply calls CopyTo(String), ignoring the fileId parameter.

Delete()

Deletes the underlying file system file.

Declaration
public override void Delete()
Overrides

InternalMoveCopy(String, Boolean)

The actual Move/Copy operation is performed here. Supports copying/moving to other virtual path providers, in which case the file is read and written as a stream

If copying/moving to the same (or anoter) native directory destination, the underlying FileInfo.CopyTo() / FileInfo.MoveTo() is used for best performance.

Declaration
protected void InternalMoveCopy(string destVirtualPath, bool isMove)
Parameters
Type Name Description
System.String destVirtualPath
System.Boolean isMove

True if a Move operation is to be performced, False if a Copy operation

MoveTo(String)

Move the file to a new location.

Declaration
public override void MoveTo(string destVirtualPath)
Parameters
Type Name Description
System.String destVirtualPath

The destination virtual path.

Overrides
Remarks

Moving between different provider types are supported. When moving the file to another NativeDirectory the underlying file system move functionality is used, otherwise the files stream is copied to the destination provider and the file is deleted in the underlying file system.

Open()

Returns a read-only stream to the file resource.

Declaration
public override Stream Open()
Returns
Type Description
System.IO.Stream

A read-only stream to the virtual file.

Overrides

Open(FileMode, FileAccess, FileShare)

Opens the file for writing given an mode with an specific share option to open the file in .

Declaration
public override Stream Open(FileMode mode, FileAccess access, FileShare share)
Parameters
Type Name Description
System.IO.FileMode mode

The file mode to use when open the file.

System.IO.FileAccess access

A FileAccess constant specifying whether to open the file with Read, Write, or ReadWrite file access.

System.IO.FileShare share

A FileShare value specifying the type of access other threads have to the file.

Returns
Type Description
System.IO.Stream

A open stream to the file.

Overrides

StreamBasedCopy(UnifiedDirectory, String)

Copies this file instance by reading the file stream and writing it to the target location.

Declaration
protected void StreamBasedCopy(UnifiedDirectory destinationDirectory, string destinationFileName)
Parameters
Type Name Description
UnifiedDirectory destinationDirectory

The destination directory.

System.String destinationFileName

Name of the destination file.

Extension Methods