當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。