当前位置: 首页>>代码示例>>C#>>正文


C# ZipArchiveEntry.ExtractToFile方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:davin8000,项目名称:File-Zipper-ONGOING,代码行数:58,代码来源:Compression.cs

示例2: ExtractToFile

 public void ExtractToFile(ZipArchiveEntry source, string destinationFileName, bool overwrite)
 {
     source.ExtractToFile(destinationFileName, overwrite);
 }
开发者ID:Xoin,项目名称:paradoxGameConverters,代码行数:4,代码来源:ZipFileProxy.cs

示例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);
		}
开发者ID:StevenArnauts,项目名称:appserver,代码行数:5,代码来源:ArchivePackage.cs

示例4: UnpackAndGetFileName

 private string UnpackAndGetFileName(ZipArchiveEntry entry, string destinationDirectory)
 {
     string pathToUnpackedFile = Path.Combine(destinationDirectory, entry.Name);
     entry.ExtractToFile(pathToUnpackedFile);
     return pathToUnpackedFile;
 }
开发者ID:piotrcierpich,项目名称:los,代码行数:6,代码来源:GalleryFilesResolver.cs


注:本文中的System.IO.Compression.ZipArchiveEntry.ExtractToFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。