System.IO.Compression.ZipFile.OpenRead C# (CSharp) Méthode

OpenRead() public static méthode

Opens a ZipArchive on the specified path for reading. The specified file is opened with FileMode.Open.
archiveFileName is a zero-length string, contains only white space, or contains one /// or more invalid characters as defined by InvalidPathChars. archiveFileName is null. The specified archiveFileName exceeds the system-defined maximum length. /// For example, on Windows-based platforms, paths must be less than 248 characters, /// and file names must be less than 260 characters. The specified archiveFileName is invalid, (for example, it is on an unmapped drive). An unspecified I/O error occurred while opening the file. archiveFileName specified a directory. /// -OR- The caller does not have the required permission. The file specified in archiveFileName was not found. archiveFileName is in an invalid format. The specified file could not be interpreted as a Zip file.
public static OpenRead ( string archiveFileName ) : ZipArchive
archiveFileName string A string specifying the path on the filesystem to open the archive on. The path is permitted /// to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory.
Résultat ZipArchive
        public static ZipArchive OpenRead(string archiveFileName)
        {
            return Open(archiveFileName, ZipArchiveMode.Read);
        }

Usage Example

        void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            this.BeginInvoke((MethodInvoker) delegate
            {
                DownloadProgress.Style = ProgressBarStyle.Marquee;

                string updatePath = Path.GetDirectoryName(Application.ExecutablePath) + "\\";
                using (ZipArchive archive = ZipFile.OpenRead(tempNameZip))
                {
                    int numFiles = archive.Entries.Count;
                    int current  = 1;

                    DownloadProgress.Style = ProgressBarStyle.Blocks;

                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        string fullName = entry.FullName;

                        if (fullName.Substring(fullName.Length - 1) == "/")
                        {
                            string folderName = fullName.Remove(fullName.Length - 1);
                            if (Directory.Exists(folderName))
                            {
                                Directory.Delete(folderName, true);
                            }

                            Directory.CreateDirectory(folderName);
                        }
                        else
                        {
                            if (fullName != "GameLauncherUpdater.exe")
                            {
                                if (File.Exists(fullName))
                                {
                                    File.Delete(fullName);
                                }

                                Information.Text = "Extracting: " + fullName;
                                try { entry.ExtractToFile(Path.Combine(updatePath, fullName)); } catch { }
                                Delay.WaitMSeconds(200);
                            }
                        }

                        DownloadProgress.Value = (int)((long)100 * current / numFiles);
                        current++;
                    }
                }

                Process.Start(@"GameLauncher.exe");
                error("Update completed. Starting GameLauncher.exe");
            });
        }
All Usage Examples Of System.IO.Compression.ZipFile::OpenRead