How to Unzip the file Using script task

  • Hi iam using script task to unzip the file.I am not good at vb.net. Can you help me in writing the code for it.

    'Unzip File

    Set WshShell = CreateObject("WScript.Shell")

    strUnZip = "..\..:\pkzip.exe -extract -over=all " & strSourceFileZip

    'msgbox strUnZip

    'WshShell.Run strUnZip,,true

    master.WriteLine strFileName & ".txt created in Doral dir @ " & now

    Set WshShell = nothing

    fso.DeleteFile strSourceFileZip

    master.WriteLine " " & strSourceFileZip & "Deleted @ " & now

    This is the code in VBscript.

    I want to write this in VB.net

    Thanks

  • This should work.....You'll need to create two variables in the package corresponding to the variables referenced below (ZipFileName and ExtractionLocation). Also you will need to add a reference to vjslib.dll

    ' Microsoft SQL Server Integration Services Script Task

    ' Write scripts using Microsoft Visual Basic

    ' The ScriptMain class is the entry point of the Script Task.

    Imports System

    Imports System.Data

    Imports System.Math

    Imports Microsoft.SqlServer.Dts.Runtime

    Imports java.util.zip

    Public Class ScriptMain

    ' The execution engine calls this method when the task executes.

    ' To access the object model, use the Dts object. Connections, variables, events,

    ' and logging features are available as static members of the Dts class.

    ' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.

    '

    ' To open Code and Text Editor Help, press F1.

    ' To open Object Browser, press Ctrl+Alt+J.

    Public Sub Main()

    Try

    Dim strSourceFile As String

    Dim strDestinationDirectory As String

    strSourceFile = Dts.Variables("ZipFileName").Value.ToString

    strDestinationDirectory = Dts.Variables("ExtractionLocation").Value.ToString

    Dim oFileInputStream As New java.io.FileInputStream(strSourceFile)

    Dim oZipInputStream As New java.util.zip.ZipInputStream(oFileInputStream)

    Dim bTrue As Boolean = True

    Dim sbBuf(1024) As SByte

    While 1 = 1

    Dim oZipEntry As ZipEntry = oZipInputStream.getNextEntry()

    If oZipEntry Is Nothing Then Exit While

    If oZipEntry.isDirectory Then

    If Not My.Computer.FileSystem.DirectoryExists(strDestinationDirectory & oZipEntry.getName) Then

    My.Computer.FileSystem.CreateDirectory(strDestinationDirectory & oZipEntry.getName)

    End If

    Else

    Dim oFileOutputStream As New java.io.FileOutputStream(strDestinationDirectory.Replace("\", "/") & oZipEntry.getName())

    While 1 = 1

    Dim iLen As Integer = oZipInputStream.read(sbBuf)

    If iLen < 0 Then Exit While

    oFileOutputStream.write(sbBuf, 0, iLen)

    End While

    oFileOutputStream.close()

    End If

    End While

    oZipInputStream.close()

    oFileInputStream.close()

    Dts.TaskResult = Dts.Results.Success

    Catch ex As Exception

    Throw New Exception(ex.Message)

    Dts.TaskResult = Dts.Results.Failure

    End Try

    Dts.TaskResult = Dts.Results.Success

    End Sub

    End Class

  • If you don't want to write any script, check the Zip Task.

    ---
    SSIS Tasks Components Scripts Services | http://www.cozyroc.com/

  • I dont have zip task in control flow..........

  • You have to install SSIS+ 1.3 library. You can download it from here. After you install, read the instructions after the installation how to enable the task in your control flow toolbox.

    ---
    SSIS Tasks Components Scripts Services | http://www.cozyroc.com/

  • CozyRoc - is this free?

  • SSIS+ is commercial library.

    ---
    SSIS Tasks Components Scripts Services | http://www.cozyroc.com/

  • Do you normally advertise on the forums like this?

    sudheer_1185 - be aware that this commercial product is $500. If you have the money, looks pretty nice, but the cost wasn't mentioned in the original post.

    http://www.cozyroc.com/purchase

  • Sudheer mentioned he doesn't have good programming skills and YES CozyRoc provides commercial products, which simplify and enhance the development experience. Do you see something wrong with that?

    ---
    SSIS Tasks Components Scripts Services | http://www.cozyroc.com/

  • I see nothing at all wrong with cool add-ons like this. In fact, in my message I mentioned that if he had the money, then he should definitely check out the product. I just wanted to point out to him that he would need to give you some $....wasn't sure if he noticed that since it wasn't pointed out.

  • I see something wrong with it when you don't state it's a commercial product upfront.:angry:

  • webooth (7/19/2010)


    I see something wrong with it when you don't state it's a commercial product upfront.:angry:

    It was stated a couple of lines below. The original post was made long time ago and was incomplete, I agree.

    ---
    SSIS Tasks Components Scripts Services | http://www.cozyroc.com/

  • This is very easy to accomplish with an Execute Process task in the control flow without having to do any scripting. If you need a concrete example, please let me know and I can post it. However, the best way to do this is to get your exact command line syntax (including any necessary flags/parameters in your particular use case), set up your variables in SSIS, and then build your expression to use as your argument in the task.

  • First go out and download winrar. Then you want to use an execute process task.

    Create a variable and assign to Standard Input Variable.

    The executable is where the program exe lives.

    Arguments: e B:\somelocation\zipfiles\*.* -o+

    Set a working directory were you'll unzip the files too.

    Window Style set to hidden.

  • 7-zip is also a pretty solid archiving utility (and free) with a good command line interface which is easy to parameterize in SSIS.

Viewing 15 posts - 1 through 15 (of 17 total)

You must be logged in to reply to this topic. Login to reply