Class CompressionUtil
Provides compression utilites.
Inheritance
Namespace: Dnn.ExportImport.Components.Common
Assembly: DotNetNuke.SiteExportImport.dll
Syntax
public static class CompressionUtil : object
Methods
| Improve this Doc View SourceAddFilesToArchive(ZipArchive, IEnumerable<String>, Int32, String)
Add files to an archive. If no archive exists, new one is created.
Declaration
public static void AddFilesToArchive(ZipArchive archive, IEnumerable<string> files, int folderOffset, string folder = null)
Parameters
Type | Name | Description |
---|---|---|
ZipArchive | archive | Source archive to write the files to. |
IEnumerable<System.String> | files | List containing path of files to add to archive. |
System.Int32 | folderOffset | Starting index(Index in file url) of the root folder in archive based on what the folder structure starts in archive. e.g. if file url is c:\dnn\files\archived\foldername\1\file.jpg and we want to add all files in foldername folder then the folder offset would be starting index of foldername. |
System.String | folder | Additional root folder to be added into archive. |
AddFileToArchive(String, String, Int32, String)
Add single file to an archive. If no archive exists, new one is created.
Declaration
public static bool AddFileToArchive(string file, string archivePath, int folderOffset, string folder = null)
Parameters
Type | Name | Description |
---|---|---|
System.String | file | Full path of file to add. |
System.String | archivePath | Full path of archive file. |
System.Int32 | folderOffset | Starting index(Index in file url) of the root folder in archive based on what the folder structure starts in archive. e.g. if file url is c:\dnn\files\archived\foldername\1\file.jpg and we want to add all files in foldername folder then the folder offset would be starting index of foldername. |
System.String | folder | Additional root folder to be added into archive. |
Returns
Type | Description |
---|---|
System.Boolean | A value indicating whether the operation succeeded. |
AddFileToArchive(ZipArchive, String, Int32, String)
Adds a file to an archive.
Declaration
public static bool AddFileToArchive(ZipArchive archive, string file, int folderOffset, string folder = null)
Parameters
Type | Name | Description |
---|---|---|
ZipArchive | archive | The archive to add to. |
System.String | file | The file to add. |
System.Int32 | folderOffset | Strips this number of characters from the front of the filename. |
System.String | folder | The folder this file should go into in the archive. |
Returns
Type | Description |
---|---|
System.Boolean | A value indicating whether the operation succeeded. |
OpenCreate(String)
Open the archive file for read and write.
Declaration
public static ZipArchive OpenCreate(string archiveFileName)
Parameters
Type | Name | Description |
---|---|---|
System.String | archiveFileName | The name of the archive. |
Returns
Type | Description |
---|---|
ZipArchive | The resulting |
UnZipArchive(String, String, Boolean)
Unzip compressed file to a folder.
Declaration
public static void UnZipArchive(string archivePath, string extractFolder, bool overwrite = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | archivePath | Full path to archive with name. |
System.String | extractFolder | Full path to the target folder. |
System.Boolean | overwrite | Overwrites the files on target if true. |
UnZipArchiveExcept(String, String, Boolean, IEnumerable<String>, Boolean)
Unzip compressed file to a folder.
Declaration
public static void UnZipArchiveExcept(string archivePath, string extractFolder, bool overwrite = true, IEnumerable<string> exceptionList = null, bool deleteFromSoure = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | archivePath | Full path to archive with name. |
System.String | extractFolder | Full path to the target folder. |
System.Boolean | overwrite | Overwrites the files on target if true. |
IEnumerable<System.String> | exceptionList | List of files to exlude from extraction. |
System.Boolean | deleteFromSoure | Delete the files from the archive after extraction. |
UnZipFileFromArchive(String, String, String, Boolean, Boolean)
Unzip a single file from an archive.
Declaration
public static void UnZipFileFromArchive(string fileName, string archivePath, string extractFolder, bool overwrite = true, bool deleteFromSoure = false)
Parameters
Type | Name | Description |
---|---|---|
System.String | fileName | Name of the file to extract. This name should match the entry name in the archive. i.e. it should include complete folder structure inside the archive. |
System.String | archivePath | Full path to archive with name. |
System.String | extractFolder | Full path to the target folder. |
System.Boolean | overwrite | Overwrites the file on target if true. |
System.Boolean | deleteFromSoure | Delete the file from the archive after extraction. |
ZipFolder(String, String)
Compress a full folder.
Declaration
public static void ZipFolder(string folderPath, string archivePath)
Parameters
Type | Name | Description |
---|---|---|
System.String | folderPath | Full path of folder to compress. |
System.String | archivePath | Full path of the archived file. |