Alex Gordon
Alex Gordon

Reputation: 60691

unzipping a file using 7zip in SSIS

I'm currently using a Process Task to try to unzip a file in SSIS with the following settings:

enter image description here

I'm using this statement:

e "Inventory.zip" -o"c:\broinctarget\" -y

I'm actually generating the above statement using:

enter image description here

"e " +"\"" + "Inventory.zip"  + "\"" + " -o" + "\"" +@[$Package::targetLocation]  +"\""+" -y"
@[$Package::targetLocation]

Am I doing something that is obviously wrong?

How do I unzip a *.zip file using 7zip in SSIS?

Upvotes: 1

Views: 7976

Answers (1)

Dave C
Dave C

Reputation: 7392

I ran into a similar issue on an SSIS package I wrote. I ended up generating a batch file in a c# script, and just calling that batch file in an execute process task.

I also needed the flexibility to add a password option based on some table parameters.

I realize it's an extra step, and if I were unzipping a ton of files it might matter, but for a For-Each container that is going to hit 5-10 files, its not a big deal - and you can easily read the batch file to see what was run too.

    string exe7z = Dts.Variables["s7ZIPPath"].Value.ToString();;
    string zipFile = Dts.Variables["sZIPFile"].Value.ToString();
    string outPath = Dts.Variables["sFileLocation"].Value.ToString();
    string password = Dts.Variables["sZIPPassword"].Value.ToString();

    if (password.Length > 0)
    {
        password = "-p\"" + password + "\"";
    }

    if (!(outPath.EndsWith("\\")))
    {
        outPath = outPath + "\\";
    }

    string batchFile = outPath + "unzip.bat";
    Dts.Variables["sZipBatchFile"].Value = batchFile;

    using (StreamWriter writer = new StreamWriter(batchFile))
    {
        writer.Write("\"" + exe7z + "\" e \"" + zipFile + "\" -o\"" + outPath + "\" -y " + password);
    }

Upvotes: 1

Related Questions