Question

I have C# program using 7za.exe to check a zip archive using the "l" command and then extract it using the "e" command. Information about 7-Zip command line can be found at: http://www.dotnetperls.com/7-zip-examples

I can run the program from my desktop on the sever and it works great, however running it directly on the server it gives the following exception: "The system cannot find the file specified". I have verified that the file path is correct and is being passed to 7za.exe. I have attached 7za.exe as an Embedded Resource in my project and not sure why it can't find the files? Any ideas? Thanks!

Here is the code I have to verify I can open the zip archive and mostly the same to unzip except the l is an e.

Process l = new Process();
l.StartInfo.FileName = "7za.exe";
l.StartInfo.Arguments = "l " + filePath[i];
l.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
l.EnableRaisingEvents = true;
l.StartInfo.UseShellExecute = false;
l.StartInfo.RedirectStandardOutput = true;
l.Start(); // This is were it throuws the exception because it can't find the file.
// Do stuff to verify zip archive is not corrupt
l.WaitForExit();

Ex: filePath[i] = C:\Users\Me\Desktop\ZipFile.zip

Was it helpful?

Solution

The "embedded resource" can only be used with the .NET resource API, it doesn't create individual files and can't be found by normal Windows functions, such as CreateProcess (which is what Process.Start uses).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top