We help IT Professionals succeed at work.
Get Started

Winform codebehind to vbscript in DTSPackage

Last Modified: 2013-11-30
I've created the following windows app code that will take a file from a directory copy it to a backup folder, unzip the file to a different directory folder and then delete the original file. This works when running it using VS2005. What I want to do is to take this and have it work as an ActiveX Script Task within a DTS package in SQL 2000.  I've tried pasting it into the DTSPackage script and removing or modifying the lines where it would error at only to end up getting the "package failed" when I tried to execute the task.

Public Class Unzip
Private Sub Unzip_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub

    Sub Unzip()
         Dim UnzipExePath = Chr(34) & "C:\UnZip\unCIP.exe" & Chr(34)
        Dim UnzipfilePath = Chr(34) & "C:\Extractunzip" & Chr(34)
        Dim filenames As String
        Dim ZipfilePath = "C:\UnZip\Test\"
        filenames = GetAllFilenames(ZipfilePath, ";")
        Dim filearray()
        filearray = Split(filenames, ";")
        'ZipfilePath = ZipfilePath & sfilename
        For i As Integer = 0 To filearray.Length - 1
            Dim file As String
            file = ZipfilePath & filearray(i)
            'Copy file to backup location
            Dim myfileInfo As New System.IO.FileInfo(file)

            If myfileInfo.Exists = True Then
                Dim Destination As String
                Destination = "C:\Extractunzip\Backup\" & Date.Now.ToString("yyyyMMdd") & filearray(i)
                System.IO.File.Copy(file, Destination, True) ' copy to the target file

                'Unzip file to pickup folder
                Dim retval As Double
                retval = Shell(UnzipExePath & " " & Chr(34) & file & Chr(34) & " " & UnzipfilePath)

                'Delete file from drop-off folder
                System.IO.File.Delete(file) 'delete source file

            End If
   End Sub

    Public Function GetAllFilenames(ByVal Directory As String, Optional ByVal Delimiter As String = vbCrLf) As String
        Dim SRet As String
        Dim sFName As String
        sFName = Dir$(Directory & "*.*", vbReadOnly Or vbHidden Or vbDirectory)

        Do Until Len(sFName) = 0
            If Len(SRet) > 0 Then
                SRet = SRet & Delimiter
            End If
            SRet = SRet & sFName
            sFName = Dir$()

        GetAllFilenames = SRet
    End Function

End Class

Thanks for your help.
Watch Question
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE