November 30, 2008 at 5:27 pm
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
December 1, 2008 at 7:47 am
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
December 1, 2008 at 11:30 am
I dont have zip task in control flow..........
December 1, 2008 at 2:25 pm
CozyRoc - is this free?
December 1, 2008 at 2:29 pm
December 1, 2008 at 2:34 pm
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.
December 1, 2008 at 2:54 pm
December 1, 2008 at 2:58 pm
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.
July 19, 2010 at 3:53 pm
I see something wrong with it when you don't state it's a commercial product upfront.:angry:
July 19, 2010 at 3:59 pm
July 20, 2010 at 9:43 am
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.
July 21, 2010 at 7:49 am
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.
July 21, 2010 at 8:26 am
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