slrine2000
asked on
Winform codebehind to vbscript in DTSPackage
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
Unzip()
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(ZipfilePat h, ";")
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("yyyyMMd d") & 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
Next
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$()
Loop
GetAllFilenames = SRet
End Function
End Class
Thanks for your help.
Public Class Unzip
Private Sub Unzip_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Unzip()
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(ZipfilePat
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("yyyyMMd
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
End If
Next
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$()
Loop
GetAllFilenames = SRet
End Function
End Class
Thanks for your help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER