2

I was wondering whether it is possible to unzip files in c sharp without using open source dll's in .net 4.0 or lower?

I have some VBA code (below) that uses the "Shell" command. Is that also possible from c sharp?

Sub UnzipMe(path)

Dim strDOSCMD As String
Dim filename As String
Dim i As Integer


filename = path + "\test.txt"
strDOSCMD = "unzip -n " + path + "\zipfile.zip -d " + path
'SEND TO DOS
retval = Shell(strDOSCMD, vbHide)


End Sub

This works fine and is very simple but I would like to do it all in c sharp and not mix and match. Surely that should be doable or there should be an equally simple solution?

Rich
  • 5,603
  • 9
  • 39
  • 61
nik
  • 1,672
  • 2
  • 17
  • 36
  • You can use 'Process.Start' http://stackoverflow.com/questions/181719/how-to-start-a-process-from-c to launch your DOS command, but consider to use a third party component – Irvin Dominin Jul 23 '13 at 09:50
  • thanks. What third party package do you recommend? – nik Jul 23 '13 at 10:29

1 Answers1

1

You can start a process in C# using Process.Start.

Your code can look like (not tested..):

public void UnzipMe(string path){
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    startInfo.FileName = "cmd.exe";
    startInfo.Arguments = "/C unzip -n " + path + "\zipfile.zip -d " + path;
    process.StartInfo = startInfo;
    process.Start();
    //do some extra stuff here
}

For zip stuff consider to use a third party library like sharpziplib I use it with success in many projects.

Take a look to these samples: https://github.com/icsharpcode/SharpZipLib/wiki/Zip-Samples

Irvin Dominin
  • 30,819
  • 9
  • 77
  • 111
  • thanks Edward. I have breifly looked at sharpziplib, do you mind posting a simply unzip function based on that package please? – nik Jul 23 '13 at 10:58
  • https://github.com/icsharpcode/SharpZipLib/wiki/Zip-Samples#wiki-anchorUnpackFull – SKull Jul 23 '13 at 11:25