• Share
    • Twitter
    • LinkedIn
    • Facebook
    • Email
  • Feedback
  • Improve this Doc

Class FileManager

Exposes methods to manage files.

Inheritance
System.Object
ComponentBase<IFileManager, FileManager>
FileManager
Implements
IFileManager
Inherited Members
ComponentBase<IFileManager, FileManager>.Instance
ComponentBase<IFileManager, FileManager>.RegisterInstance(IFileManager)
Namespace: DotNetNuke.Services.FileSystem
Assembly: DotNetNuke.dll
Syntax
public class FileManager : ComponentBase<IFileManager, FileManager>, IFileManager

Properties

| Improve this Doc View Source

ContentTypes

Gets the system defined content types.

Declaration
public virtual IDictionary<string, string> ContentTypes { get; }
Property Value
Type Description
IDictionary<System.String, System.String>
| Improve this Doc View Source

WhiteList

Gets current user's file upload extension whitelist.

Declaration
public FileExtensionWhitelist WhiteList { get; }
Property Value
Type Description
FileExtensionWhitelist

Methods

| Improve this Doc View Source

AddFile(IFolderInfo, String, Stream, Boolean, Boolean, Boolean, String, Int32)

Adds a file to the specified folder.

Declaration
public virtual IFileInfo AddFile(IFolderInfo folder, string fileName, Stream fileContent, bool overwrite, bool checkPermissions, bool ignoreWhiteList, string contentType, int createdByUserID)
Parameters
Type Name Description
IFolderInfo folder

The folder where to add the file.

System.String fileName

The name of the file.

Stream fileContent

The content of the file.

System.Boolean overwrite

Indicates if the file has to be over-written if it exists.

System.Boolean checkPermissions

Indicates if permissions have to be met.

System.Boolean ignoreWhiteList

Indicates whether the whitelist should be ignored.

System.String contentType

The content type of the file.

System.Int32 createdByUserID

ID of the user that creates the file.

Returns
Type Description
IFileInfo

A IFileInfo as specified by the parameters.

Exceptions
Type Condition
FolderProviderException

Thrown when the underlying system throw an exception.

InvalidFileExtensionException

Thrown when the extension of the specified file is not allowed.

NoSpaceAvailableException

Thrown when the portal has no space available to store the specified file.

PermissionsNotMetException

Thrown when permissions are not met.

| Improve this Doc View Source

AddFile(IFolderInfo, String, Stream, Boolean, Boolean, String, Int32)

Adds a file to the specified folder.

Declaration
public virtual IFileInfo AddFile(IFolderInfo folder, string fileName, Stream fileContent, bool overwrite, bool checkPermissions, string contentType, int createdByUserID)
Parameters
Type Name Description
IFolderInfo folder

The folder where to add the file.

System.String fileName

The name of the file.

Stream fileContent

The content of the file.

System.Boolean overwrite

Indicates if the file has to be over-written if it exists.

System.Boolean checkPermissions

Indicates if permissions have to be met.

System.String contentType

The content type of the file.

System.Int32 createdByUserID

ID of the user that creates the file.

Returns
Type Description
IFileInfo

A IFileInfo as specified by the parameters.

Exceptions
Type Condition
FolderProviderException

Thrown when the underlying system throw an exception.

InvalidFileExtensionException

Thrown when the extension of the specified file is not allowed.

NoSpaceAvailableException

Thrown when the portal has no space available to store the specified file.

PermissionsNotMetException

Thrown when permissions are not met.

| Improve this Doc View Source

AddFile(IFolderInfo, String, Stream, Boolean, Boolean, String)

Adds a file to the specified folder.

Declaration
public virtual IFileInfo AddFile(IFolderInfo folder, string fileName, Stream fileContent, bool overwrite, bool checkPermissions, string contentType)
Parameters
Type Name Description
IFolderInfo folder

The folder where to add the file.

System.String fileName

The name of the file.

Stream fileContent

The content of the file.

System.Boolean overwrite

Indicates if the file has to be over-written if it exists.

System.Boolean checkPermissions

Indicates if permissions have to be met.

System.String contentType

The content type of the file.

Returns
Type Description
IFileInfo

A IFileInfo as specified by the parameters.

Exceptions
Type Condition
FolderProviderException

Thrown when the underlying system throw an exception.

InvalidFileExtensionException

Thrown when the extension of the specified file is not allowed.

NoSpaceAvailableException

Thrown when the portal has no space available to store the specified file.

PermissionsNotMetException

Thrown when permissions are not met.

| Improve this Doc View Source

AddFile(IFolderInfo, String, Stream, Boolean)

Adds a file to the specified folder.

Declaration
public virtual IFileInfo AddFile(IFolderInfo folder, string fileName, Stream fileContent, bool overwrite)
Parameters
Type Name Description
IFolderInfo folder

The folder where to add the file.

System.String fileName

The name of the file.

Stream fileContent

The content of the file.

System.Boolean overwrite

Indicates if the file has to be over-written if it exits.

Returns
Type Description
IFileInfo

A IFileInfo as specified by the parameters.

| Improve this Doc View Source

AddFile(IFolderInfo, String, Stream)

Adds a file to the specified folder.

Declaration
public virtual IFileInfo AddFile(IFolderInfo folder, string fileName, Stream fileContent)
Parameters
Type Name Description
IFolderInfo folder

The folder where to add the file.

System.String fileName

The name of the file.

Stream fileContent

The content of the file.

Returns
Type Description
IFileInfo

A IFileInfo as specified by the parameters.

| Improve this Doc View Source

CopyFile(IFileInfo, IFolderInfo)

Copies the specified file into the specified folder.

Declaration
public virtual IFileInfo CopyFile(IFileInfo file, IFolderInfo destinationFolder)
Parameters
Type Name Description
IFileInfo file

The file to copy.

IFolderInfo destinationFolder

The folder where to copy the file to.

Returns
Type Description
IFileInfo

A IFileInfo with the information of the copied file.

| Improve this Doc View Source

DeleteFile(IFileInfo)

Deletes the specified file.

Declaration
public virtual void DeleteFile(IFileInfo file)
Parameters
Type Name Description
IFileInfo file

The file to delete.

Exceptions
Type Condition
FolderProviderException

Thrown when the underlying system throw an exception.

| Improve this Doc View Source

DeleteFiles(IEnumerable<IFileInfo>)

Deletes the specified files.

Declaration
public virtual void DeleteFiles(IEnumerable<IFileInfo> files)
Parameters
Type Name Description
IEnumerable<IFileInfo> files

The files to delete.

| Improve this Doc View Source

FileExists(IFolderInfo, String, Boolean)

Checks the existence of the specified file in the specified folder.

Declaration
public virtual bool FileExists(IFolderInfo folder, string fileName, bool retrieveUnpublishedFiles)
Parameters
Type Name Description
IFolderInfo folder

The folder where to check the existence of the file.

System.String fileName

The file name to check the existence of.

System.Boolean retrieveUnpublishedFiles

Indicates if the file is retrieved from All files or from Published files.

Returns
Type Description
System.Boolean

A bool value indicating whether the file exists or not in the specified folder.

Exceptions
Type Condition
FolderProviderException

Thrown when the underlying system throw an exception.

| Improve this Doc View Source

FileExists(IFolderInfo, String)

Checks the existence of the specified file in the specified folder.

Declaration
public virtual bool FileExists(IFolderInfo folder, string fileName)
Parameters
Type Name Description
IFolderInfo folder

The folder where to check the existence of the file.

System.String fileName

The file name to check the existence of.

Returns
Type Description
System.Boolean

A bool value indicating whether the file exists or not in the specified folder.

Exceptions
Type Condition
FolderProviderException

Thrown when the underlying system throw an exception.

| Improve this Doc View Source

GetContentType(String)

Gets the Content Type for the specified file extension.

Declaration
public virtual string GetContentType(string extension)
Parameters
Type Name Description
System.String extension

The file extension.

Returns
Type Description
System.String

The Content Type for the specified extension.

| Improve this Doc View Source

GetFile(IFolderInfo, String, Boolean)

Gets the file metadata for the specified file.

Declaration
public virtual IFileInfo GetFile(IFolderInfo folder, string fileName, bool retrieveUnpublishedFiles)
Parameters
Type Name Description
IFolderInfo folder

The folder where the file is stored.

System.String fileName

The name of the file.

System.Boolean retrieveUnpublishedFiles

Indicates if the file is retrieved from All files or from Published files.

Returns
Type Description
IFileInfo

The IFileInfo object with the metadata of the specified file.

| Improve this Doc View Source

GetFile(IFolderInfo, String)

Gets the file metadata for the specified file.

Declaration
public virtual IFileInfo GetFile(IFolderInfo folder, string fileName)
Parameters
Type Name Description
IFolderInfo folder

The folder where the file is stored.

System.String fileName

The name of the file.

Returns
Type Description
IFileInfo

The IFileInfo object with the metadata of the specified file.

| Improve this Doc View Source

GetFile(Int32, Boolean)

Gets the file metadata for the specified file.

Declaration
public virtual IFileInfo GetFile(int fileID, bool retrieveUnpublishedFiles)
Parameters
Type Name Description
System.Int32 fileID

The file identifier.

System.Boolean retrieveUnpublishedFiles

Indicates if the file is retrieved from All files or from Published files.

Returns
Type Description
IFileInfo

The IFileInfo object with the metadata of the specified file.

| Improve this Doc View Source

GetFile(Int32, String, Boolean)

Gets the file metadata for the specified file.

Declaration
public virtual IFileInfo GetFile(int portalId, string relativePath, bool retrieveUnpublishedFiles)
Parameters
Type Name Description
System.Int32 portalId

The portal ID or Null.NullInteger for the Host.

System.String relativePath

Relative path to the file.

System.Boolean retrieveUnpublishedFiles

Indicates if the file is retrieved from All files or from Published files.

Returns
Type Description
IFileInfo

The IFileInfo object with the metadata of the specified file.

Remarks

Host and portal settings commonly return a relative path to a file. This method uses that relative path to fetch file metadata.

| Improve this Doc View Source

GetFile(Int32, String)

Gets the file metadata for the specified file.

Declaration
public virtual IFileInfo GetFile(int portalId, string relativePath)
Parameters
Type Name Description
System.Int32 portalId

The portal ID or Null.NullInteger for the Host.

System.String relativePath

Relative path to the file.

Returns
Type Description
IFileInfo

The IFileInfo object with the metadata of the specified file.

Remarks

Host and portal settings commonly return a relative path to a file. This method uses that relative path to fetch file metadata.

| Improve this Doc View Source

GetFile(Int32)

Gets the file metadata for the specified file.

Declaration
public virtual IFileInfo GetFile(int fileID)
Parameters
Type Name Description
System.Int32 fileID

The file identifier.

Returns
Type Description
IFileInfo

The IFileInfo object with the metadata of the specified file.

| Improve this Doc View Source

GetFileContent(IFileInfo)

Gets the content of the specified file.

Declaration
public virtual Stream GetFileContent(IFileInfo file)
Parameters
Type Name Description
IFileInfo file

The file to get the content from.

Returns
Type Description
Stream

A stream with the content of the file.

Exceptions
Type Condition
FolderProviderException

Thrown when the underlying system throw an exception.

| Improve this Doc View Source

GetSeekableStream(Stream)

Gets a seekable Stream based on the specified non-seekable Stream.

Declaration
public virtual Stream GetSeekableStream(Stream stream)
Parameters
Type Name Description
Stream stream

A non-seekable Stream.

Returns
Type Description
Stream

A seekable Stream.

| Improve this Doc View Source

GetUrl(IFileInfo)

Gets the direct URL to the file.

Declaration
public string GetUrl(IFileInfo file)
Parameters
Type Name Description
IFileInfo file

The file to get the Url.

Returns
Type Description
System.String

The direct URL to the file.

Exceptions
Type Condition
FolderProviderException

Thrown when the underlying system throw an exception.

| Improve this Doc View Source

IsImageFile(IFileInfo)

Gets a flag that determines if the file is an Image.

Declaration
public virtual bool IsImageFile(IFileInfo file)
Parameters
Type Name Description
IFileInfo file

The file to test.

Returns
Type Description
System.Boolean

The flag as a boolean value.

| Improve this Doc View Source

MoveFile(IFileInfo, IFolderInfo)

Moves the specified file into the specified folder.

Declaration
public virtual IFileInfo MoveFile(IFileInfo file, IFolderInfo destinationFolder)
Parameters
Type Name Description
IFileInfo file

The file to move.

IFolderInfo destinationFolder

The folder where to move the file to.

Returns
Type Description
IFileInfo

An IFileInfo with the information of the moved file.

Exceptions
Type Condition
FolderProviderException

Thrown when the underlying system throw an exception.

InvalidFileExtensionException

Thrown when the extension of the specified file is not allowed.

NoSpaceAvailableException

Thrown when the portal has no space available to store the specified file.

PermissionsNotMetException

Thrown when permissions are not met.

| Improve this Doc View Source

RenameFile(IFileInfo, String)

Renames the specified file.

Declaration
public virtual IFileInfo RenameFile(IFileInfo file, string newFileName)
Parameters
Type Name Description
IFileInfo file

The file to rename.

System.String newFileName

The new filename to assign to the file.

Returns
Type Description
IFileInfo

An IFileInfo with the information of the renamed file.

Exceptions
Type Condition
FileAlreadyExistsException

Thrown when the folder already contains a file with the same name.

| Improve this Doc View Source

SetAttributes(IFileInfo, FileAttributes)

Sets the specified FileAttributes of the file.

Declaration
public void SetAttributes(IFileInfo file, FileAttributes fileAttributes)
Parameters
Type Name Description
IFileInfo file

The file.

FileAttributes fileAttributes

The file attributes to add.

| Improve this Doc View Source

UnzipFile(IFileInfo, IFolderInfo, IList<String>)

Extracts the files and folders contained in the specified zip file to the specified folder.

Declaration
public virtual int UnzipFile(IFileInfo file, IFolderInfo destinationFolder, IList<string> invalidFiles)
Parameters
Type Name Description
IFileInfo file

The file to unzip.

IFolderInfo destinationFolder

The folder to unzip to.

IList<System.String> invalidFiles

Files which can't exact.

Returns
Type Description
System.Int32

Total files count in the zip file.

| Improve this Doc View Source

UnzipFile(IFileInfo, IFolderInfo)

Extracts the files and folders contained in the specified zip file to the specified folder.

Declaration
public virtual void UnzipFile(IFileInfo file, IFolderInfo destinationFolder)
Parameters
Type Name Description
IFileInfo file

The file to unzip.

IFolderInfo destinationFolder

The folder to unzip to.

| Improve this Doc View Source

UnzipFile(IFileInfo)

Extracts the files and folders contained in the specified zip file to the folder where the file belongs.

Declaration
public virtual void UnzipFile(IFileInfo file)
Parameters
Type Name Description
IFileInfo file

The file to unzip.

| Improve this Doc View Source

UpdateFile(IFileInfo, Stream)

Regenerates the hash and updates the metadata of the specified file.

Declaration
public virtual IFileInfo UpdateFile(IFileInfo file, Stream fileContent)
Parameters
Type Name Description
IFileInfo file

The file to update.

Stream fileContent

Stream used to regenerate the hash.

Returns
Type Description
IFileInfo

A IFileInfo as the updated file.

| Improve this Doc View Source

UpdateFile(IFileInfo)

Updates the metadata of the specified file.

Declaration
public virtual IFileInfo UpdateFile(IFileInfo file)
Parameters
Type Name Description
IFileInfo file

The file to update.

Returns
Type Description
IFileInfo

A IFileInfo as the updated file.

Exceptions
Type Condition
InvalidMetadataValuesException

Thrown when the file metadata are not valid.

| Improve this Doc View Source

WriteFile(IFileInfo, Stream)

Writes the content of the specified file into the specified stream.

Declaration
public virtual void WriteFile(IFileInfo file, Stream stream)
Parameters
Type Name Description
IFileInfo file

The file to write into the stream.

Stream stream

The stream to write to.

| Improve this Doc View Source

WriteFileToResponse(IFileInfo, ContentDisposition)

Downloads the specified file.

Declaration
public virtual void WriteFileToResponse(IFileInfo file, ContentDisposition contentDisposition)
Parameters
Type Name Description
IFileInfo file

The file to download.

ContentDisposition contentDisposition

Indicates how to display the document once downloaded.

Exceptions
Type Condition
PermissionsNotMetException

Thrown when permissions are not met.

Implements

IFileManager

Extension Methods

JsonExtensionsWeb.ToJson(Object)
  • View Source
Back to top by the community, for the community... #DNNCMS