本文整理汇总了C#中System.IO.Compression.ZipArchiveEntry.ExtractToFile方法的典型用法代码示例。如果您正苦于以下问题:C# ZipArchiveEntry.ExtractToFile方法的具体用法?C# ZipArchiveEntry.ExtractToFile怎么用?C# ZipArchiveEntry.ExtractToFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Compression.ZipArchiveEntry
的用法示例。
在下文中一共展示了ZipArchiveEntry.ExtractToFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImprovedExtractToFile
/// <summary>
/// Safely extracts a single file from a zip file
/// </summary>
/// <param name="file">
/// The zip entry we are pulling the file from
/// </param>
/// <param name="destinationPath">
/// The root of where the file is going
/// </param>
/// <param name="overwriteMethod">
/// Specifies how we are going to handle an existing file.
/// The default is Overwrite.IfNewer.
/// </param>
public static void ImprovedExtractToFile(ZipArchiveEntry file,
string destinationPath,
Overwrite overwriteMethod = Overwrite.IfNewer)
{
//Gets the complete path for the destination file, including any
//relative paths that were in the zip file
string destinationFileName = Path.Combine(destinationPath, file.FullName);
//Gets just the new path, minus the file name so we can create the
//directory if it does not exist
string destinationFilePath = Path.GetDirectoryName(destinationFileName);
//Creates the directory (if it doesn't exist) for the new path
Directory.CreateDirectory(destinationFilePath);
//Determines what to do with the file based upon the
//method of overwriting chosen
switch (overwriteMethod)
{
case Overwrite.Always:
//Just put the file in and overwrite anything that is found
file.ExtractToFile(destinationFileName, true);
break;
case Overwrite.IfNewer:
//Checks to see if the file exists, and if so, if it should
//be overwritten
if (!File.Exists(destinationFileName) || File.GetLastWriteTime(destinationFileName) < file.LastWriteTime)
{
//Either the file didn't exist or this file is newer, so
//we will extract it and overwrite any existing file
file.ExtractToFile(destinationFileName, true);
}
break;
case Overwrite.Never:
//Put the file in if it is new but ignores the
//file if it already exists
if (!File.Exists(destinationFileName))
{
file.ExtractToFile(destinationFileName);
}
break;
default:
break;
}
}
示例2: ExtractToFile
public void ExtractToFile(ZipArchiveEntry source, string destinationFileName, bool overwrite)
{
source.ExtractToFile(destinationFileName, overwrite);
}
示例3: ExtractEntry
private void ExtractEntry(ZipArchiveEntry entry, string destinationPath, bool overwrite = false) {
string destinationFolder = Path.GetDirectoryName(destinationPath);
if(destinationFolder != null && !Directory.Exists(destinationFolder)) Directory.CreateDirectory(destinationFolder);
if(overwrite || !File.Exists(destinationPath)) entry.ExtractToFile(destinationPath, true);
}
示例4: UnpackAndGetFileName
private string UnpackAndGetFileName(ZipArchiveEntry entry, string destinationDirectory)
{
string pathToUnpackedFile = Path.Combine(destinationDirectory, entry.Name);
entry.ExtractToFile(pathToUnpackedFile);
return pathToUnpackedFile;
}