-1

How to execute winzip command from MVC controller Action?

Command:

C:\Program Files (x86)\WinZip>WZZIP.EXE -ys2048000 Location Location
Nate
  • 30,286
  • 23
  • 113
  • 184
Sahil Gupta
  • 13
  • 1
  • 8
  • 1
    Please provide more details about what you are trying to accomplish. There are libraries that can compress and uncompress streams without having to execute programs external to the web application. It generally doesn't make sense to do this. – NightOwl888 Mar 12 '15 at 04:49
  • I am trying to split the zip file on a particular location and then drop it on the other location. When i am trying this command through cmd it is working fine – Sahil Gupta Mar 12 '15 at 04:56
  • I cannot use any third party library or dll. If it is provided by Microsoft library let me know otherwise i need to run this command only. – Sahil Gupta Mar 12 '15 at 05:05
  • Split the zip file how? Why would you want to do this from a controller action? Is the file being uploaded? What is the workflow? What is the source? What is the destination? – NightOwl888 Mar 12 '15 at 05:26
  • This command will split the file. Splitting the zip file on a button click. Source is first Location and Destination is second location in command. That is hard coded – Sahil Gupta Mar 12 '15 at 05:30

2 Answers2

1

What you are asking, directly is possible with the System.Diagnostics.Process.Start(string, string) method. It would look something like this:

System.Diagnostics.Process.Start(
    @"C:\Program Files (x86)\WinZip\WZZIP.EXE", 
    "-ys2048000 Location Location");

I've gone down this path and for simple things it is probably good enough. I've often found that there are usually more cool, useful things you can do interacting directly with the zip files. In that case, something like DotNetZip or SharpZip are probably good alternatives. I've used DotNetZip before, its very robust and highly performant.

Here's a quick example from DotNetZip home page:

Here's some C# code that creates a zip file.

using (ZipFile zip = new ZipFile())
{
    // add this map file into the "images" directory in the zip archive
    zip.AddFile("c:\\images\\personal\\7440-N49th.png", "images");
    // add the report into a different directory in the archive
    zip.AddFile("c:\\Reports\\2008-Regional-Sales-Report.pdf", "files");
    zip.AddFile("ReadMe.txt");
    zip.Save("MyZipFile.zip");
}
Nate
  • 30,286
  • 23
  • 113
  • 184
  • @SahilGupta I'm not sure what you mean, only licensed version. DotNetZip is Microsoft Public License (Ms-PL). – Nate Mar 16 '15 at 19:00
0

I would add the following package and use that rather than trying to connect to an exe file (which you'll more than likely not have permission to do so):

https://www.nuget.org/packages/DotNetZip/

scgough
  • 5,099
  • 3
  • 30
  • 48