简体   繁体   中英

C# .net4.5 Unpack Zip file

I have made an automatic update system, and after I download the zip file, I want to unpack of course. If I am using simple unpack, its working.

//System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, extractPath);

But when I want to overwrite the files, than the application crash all the time. "An exception of type 'System.IO.IOException' occurred in mscorlib.dll but was not handled in user code" "The filename, the foldername or the label syntax not correct."

string zipPath = @""+ System.IO.Directory.GetCurrentDirectory() + "/Temp/"+"1.zip";
            string extractPath = @""+ System.IO.Directory.GetCurrentDirectory();

            using (ZipArchive archive = ZipFile.OpenRead(zipPath))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    entry.ExtractToFile(Path.Combine(extractPath, entry.FullName),true);
                }
            }

I cant figure out whats the problem. I am using something bad?

            string zipPath = @""+ System.IO.Directory.GetCurrentDirectory() + "/Temp/"+ currentupdate+".zip";
            string extractPath = @""+ System.IO.Directory.GetCurrentDirectory() + "/Temp";

            using (ZipArchive archive = ZipFile.OpenRead(zipPath))
            {
                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                    string fullPath = Path.Combine(extractPath, entry.FullName);
                    if (String.IsNullOrEmpty(entry.Name))
                    {
                        Directory.CreateDirectory(fullPath);
                    }
                    else
                    {
                       entry.ExtractToFile(fullPath,true);
                    }
                }
            }

That was the right solution. Thanks for the help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM