Ostap Filipenko
Ostap Filipenko

Reputation: 239

Check the existance of path with .zip in the path

Is there any possible solutions for C# how to check if the file exists even if the file is located in the .zip directory?

A possible path would be: "\\127.0.0.1\ZIP-Bug-Study\TestResultMap\market_coupling_ntc_preoptimization\temp.zip\file.csv"

I would need a solution without splitting the string and so on, simply something like:

FileInfo fi = new FileInfo(path);
if (fi.Exists) { }

Upvotes: 1

Views: 726

Answers (1)

redParrot
redParrot

Reputation: 470

With .Net Framework 4.5 and ZipArchive

using (ZipArchive archive = ZipFile.Open(zipPath, ZipArchiveMode.Open)){
     try{
        ZipArchiveEntry entry = archive.GetEntry("Existing Filepath with name"); // use entry then
     }
     catch(ex Exception ) { if(ex is ArgumentNullException || ex is ArgumentException) Console.Write("file not found"); }}

Replace ZipArchiveMode.Open with update if you need modifying the file.

Upvotes: 1

Related Questions