blue piranha
blue piranha

Reputation: 3874

7-zip compression in asp.net web site

I am trying to use 7-zip compression to create a zip of a sample file as given in the example http://www.dotnetperls.com/7-zip As the URL says, "you must specify "Copy if newer" or "Copy always" to copy files such as executables to the output directory."

I found that when I use this code in a VS Project, I do get the option to specify "Copy if newer" when I see properties of 7za.exe in the properties window

But when I use in a VS Web site, I am unable to find this option. As a result, when I debug this program, it saying that its unable to find 7za.exe

string sourceName = "pdfSample.pdf";
string targetName = "pdfSample.gz";

ProcessStartInfo p = new ProcessStartInfo();
p.FileName = "7za.exe";

p.Arguments = "a -tgzip \"" + targetName + "\" \"" + sourceName + "\" -mx=9";
p.WindowStyle = ProcessWindowStyle.Hidden;

try
{
    Process x = Process.Start(p);
    x.WaitForExit();
}
catch (Exception ex)
{
    Console.Write(ex.ToString());
} 

Any idea why there is no "Copy if newer" option in case of VS Web site?

Thanks!

Upvotes: 3

Views: 1308

Answers (2)

Uwe Keim
Uwe Keim

Reputation: 40736

Personally, I would never dare to start a new process from within an ASP.NET application.

The reason is that I don't know whether the process may or may not show up some windows or do other things like single-instance.

If I had to solve your requirement, I would use a class library to work with 7zip files.

Upvotes: 1

tgolisch
tgolisch

Reputation: 6734

You need to include the path for 7za.exe. Keep in mind that the web page is running under the account of the anonymous user or the app pool. Those accounts need to also have permissions to the path and exe for 7zip.

Upvotes: 2

Related Questions