I tried zip all files in a folder, and save them to another folder.
Error:
That name specifies an existing directory. Please specify a filename. Parameter Name: fileName
AppConfig:
<appSettings>
<add key="ZipLocation" value="c:\example\start"/>
<add key="ZipSaveLocation" value="c:\example\extract"/>
</appSettings>
Code:
//using Ionic.Zip;
static void Main(string[] args)
{
string startPath = ConfigurationManager.AppSettings["ZipLocation"].ToString();
string zipPath = ConfigurationManager.AppSettings["ZipSaveLocation"].ToString();
int key = Convert.ToInt32(Console.ReadLine());
try
{
using (ZipFile zip = new ZipFile())
{
String[] filenames = System.IO.Directory.GetFiles(startPath);
foreach (String filename in filenames)
{
Console.WriteLine("Adding {0}...", filename);
ZipEntry e = zip.AddFile(filename);
e.Comment = "bla bla.";
}
zip.Comment = String.Format("This zip archive was created by the CreateZip example application on machine '{0}'", System.Net.Dns.GetHostName());
zip.Save(zipPath);
}
}
catch (Exception)
{
throw;
}
}
You have this:
and then you call this:
zipPath is not a file, it's a folder.
Fix your code by doing something like: