THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

Jorg Klein

Microsoft Data Platform MVP from the Netherlands

SSIS – Unpack a ZIP file with the Script Task

You can read this blog post at this link:

This blog has moved to There will be no further posts on Please update your feeds accordingly.

You can follow me on twitter:

Published Thursday, August 27, 2009 11:57 PM by jorg

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS



dsu said:


CAN U PLEASE SHARE HOW U DID CHECK "if a file already exist in execute sql task "

Thanks in advance

May 23, 2010 1:54 AM

Jorg Klein said:

Quite often one or more sources for a data warehouse consist of flat files. Most of the times these files

May 28, 2010 7:53 AM

dsu said:


Thanks for comments But i figured it out however, i was expecting different answer.

thanks again

June 2, 2010 8:37 PM

Rahul barpha said:

Hello Jorg Klein,

Excellent artical. I really like this but your code is in j# can you please provide me same code in C#. It will really help me.



June 18, 2010 9:01 AM

jorg said:

Hi Rahul,

The code is in 'Microsoft Visual Basic 2008' and is ready to use in a script task. If you really need C# I advice you to search for a code converter...

Good luck!


June 18, 2010 10:01 AM

campster said:

why not to use external tools for unzipping files?

October 28, 2010 2:49 AM

Prabhat Nath said:

Can you please extend this to extract one single file from the .ZIP file please? I need this and dropped here during google.



October 28, 2010 2:41 PM

Ankur said:

Hi Jorq

Can you please send the script for zipping the files


July 15, 2011 3:03 PM

Ratna said:

Hi Jorg,

I used the same method as yours.

Previously I worked fine.But this month, the zip file size is increased to 288 MB (After Manual unzip it is 5.58 GB files)

And this script task failed with this error msg :

Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: compressionMethod used: 9 (neither STORED nor DEFLATED)

Do you know how to handle this case?

Thanks in Advance

June 5, 2012 12:12 AM

Graeme said:

Hi Jorg,

Your method works brilliantly for us, even extended this by making this a parameters driven callable package.

However, we now need to do the same thing for an external file that is supplied to us in .GZ format. Is there a similar java or other utility we can call from SSIS to unzip these types of files? May well need to deal with 7zip file soon as well.

And before anyone assks, no we cannot request the format to be changed, as this is the standard format the data ias delivered in, and we are expected to handle it. We can do it manually, but that sort of defeats the whole purpose of "automating" the loading process.



September 27, 2012 2:02 AM

Karl said:

stement is not valid  in name space

End Class must be preceded by a matching class

I pasted your script I ge the the erros above

October 1, 2012 5:38 PM

Karl said:

I fixed the script and now it does not complain. but the following happens. The last task to unzip file blinks green a few time and says complete but no files were unzipped.

October 1, 2012 7:16 PM

Ryan said:

Good lord Jorg, these guys writing in reply to your extremely helpful article are freaking LAZY!!

They should use this as a sample for what's possible in SSIS and configure what you've provided to use in their own environment...  

I'm so used to seeing this when we interface with typical IT folks where everything has to be spoon fed...  Try paying attention and LEARNING what Jorg did instead of looking to take his guide and using it without any idea of what's going on...  


March 7, 2013 1:30 PM

AnilKumar said:

Hi Jorg,

Can you please help me,

I am getting below errors.

at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)

  at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)

  at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)

  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()



April 26, 2013 3:40 AM

Narendra said:

Hi Jorg,

Thanks for the great article , i have a doubt here , what if the zip files are having the passwords ? how can we handle in the script task ?

Awaiting for your reply



August 27, 2013 12:54 PM

Gabe said:


I like your solution, however I'm migrating to 2012 and seems like the library is not recognized by the system. Appreciate your input.



September 8, 2014 4:31 PM

Aditya said:


I used this solution. it is working brilliantly in my development environment but, when I move it to the testing environment and run it using a scheduler, it is throwing an error which is indicated below:

Error: 2015-06-22 09:46:02.04                                                  

  Code: 0x00000002                                                            

  Source: SCT UNZIP FILE                                                      

  Description: The script threw an exception: Exception of type '' was thrown.

End Error                                                                      

any thoughts?

June 23, 2015 6:33 AM

Aditya said:

I found the issue. the issue was with the FTP download prior to this task.

June 26, 2015 9:59 AM

sundar said:

will it work for if .zip contain multiple inner sub folders?

August 4, 2017 5:52 AM

Leave a Comment


About jorg

Jorg Klein, Microsoft Data Platform MVP from the Netherlands.
Privacy Statement