1

This is my requirement, I need to extract files from password protected zipped files. I would like to know if there are any code snippets available. I am using SSIS to download these zipped files from an FTP. Is there any latest update to the 4.5 framework which I can make use of.

Update:

I have now referenced the file and tried out an example but now I am getting an exception, I even tried to add a breakpoint in my script task but still what I get is only an exception.

Exception:

   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

Snapshot: enter image description here

Code:

try
    {
            string zipfilePath = @"C:\ZipFiles";
            string zipPassword = "qwerty";
        using (ZipFile zip = new ZipFile())
        {
            zip.Password = zipPassword;
            zip.AddFile("File-01.txt");
            zip.AddFile("File-02.txt");
            zip.AddFile("File-03.txt");
            zip.AddFile("File-04.txt");
            zip.Save(zipfilePath + "AllFiles.zip");
        }
    }
    catch (Exception e)
    {
        MessageBox.Show(e.ToString());
    }

PS: I am new to C#

Prakazz
  • 421
  • 1
  • 8
  • 21
  • Can you please provide the whole exception, in particular the message associated with that error plus any inner exceptions? – AHowgego Feb 18 '15 at 10:42
  • Like I said before I tried with a breakpoint inside the code, but it is not even going to that line, all I get is this exception. – Prakazz Feb 18 '15 at 11:19
  • ... So is the exception even being thrown by the call to the DotNetZip API? It's really hard to know what's going on without seeing the code, but it seems like you might have other issues here – AHowgego Feb 18 '15 at 12:57
  • Ok Will provide the code too !! – Prakazz Feb 18 '15 at 14:13
  • Ok your problem seems to be external to the subject of our discussion here, I believe the library is behaving as designed. After a quick google, you might want to check out the message thread [here](https://social.msdn.microsoft.com/Forums/sqlserver/en-US/ba3d35f7-fa13-4fc3-8c38-95f0f463ea89/ssis-script-task-errors-when-trying-to-connect-to-sharepoint-using-client-object-model?forum=sqlintegrationservices). At a glance, some other people seem to have had a very similar problem using SSIS. If you're still having issues once this is addressed please let me know – AHowgego Feb 18 '15 at 14:33
  • Found the issue with it, Like i had said earlier this assmebly also needs to be registered in GAC for it to be called from SSIS. – Prakazz Feb 19 '15 at 04:35

1 Answers1

7

DotNetZip supports password protection. It's available as a NuGet package and allows you to extract from a password protected zip file as follows (taken and modified from the link):

string baseDirectory = "C:\\output";
string password = "password";

using (ZipFile zip = ZipFile.Read("MyArchive.zip"))
{
    ZipEntry e = zip["MyFile.txt"];
    e.ExtractWithPassword(baseDirectory, password);
}

There are lots of other "code-snippets" like this on the C# examples page I linked you.

AHowgego
  • 592
  • 6
  • 20
  • I downloaded the zip and added as a reference !! But I am getting an exception, so should this assembly be registered in GAC ? – Prakazz Feb 18 '15 at 06:10
  • 2
    No this isn't a GAC assembly, it's a third-party package. From your package manager console, run `Install-Package DotNetZip` and then add a reference in your project to `Ionic.Zip`. What does your exception say? – AHowgego Feb 18 '15 at 10:05
  • Installation done. Still having the same issue. I am editing the question with the exception. – Prakazz Feb 18 '15 at 10:20