VB ScriptTask in SSIS

  • I have no OOP languages under my belt. I've been given an SSIS package that a predecessor wrote that has some script tasks. Can somebody please help me with this really simple question?

    She's renaming a file by appending today's date as part of the file name. I need to capture that "finished" filename to a variable. This is her code. I know how to declare the variable I want to hold the name within ssis, but how do I tell this script task to write that "DestPath" to my variable?

    Public Sub Main()

    Dim SourcePath As String = FileIO.FileSystem.CombinePath(Dts.Variables("strFilePathEditDropBox").Value(), Dts.Variables("strFileDropBox").Value())

    Dim DestPath As String = FileIO.FileSystem.CombinePath(Dts.Variables("strFilePathEditDropBox").Value(), Format(Now(), "yyyyMMddhhmmss").ToString() & "_" & Dts.Variables("strFileDropBox").Value())

    Try

    FileIO.FileSystem.CopyFile(SourcePath, DestPath)

    FileIO.FileSystem.DeleteFile(SourcePath)

    Dts.TaskResult = ScriptResults.Success

    Catch ex As Exception

    Dts.TaskResult = ScriptResults.Failure

    End Try

    End Sub

    End Class

  • how do I tell this script task to write that "DestPath" to my variable?

    Three steps:

    1. Set up a variable to hold the changed file name. For this example I'm going to call it NewName.

    2. In the script task editor, list NewName in the ReadWriteVariables on the Script screen.

    3. In the Script code, add a line that says:

    Dts.Variables("NewName").Value = DestPath

    FileIO.FileSystem.CopyFile(SourcePath, DestPath)

    FileIO.FileSystem.DeleteFile(SourcePath)

    Dts.Variables("NewName").Value = DestPath

    Dts.TaskResult = ScriptResults.Success

    That should take care of it.

  • That worked perfectly and was exactly what I needed.

    Thanks so much!!

  • You're quite welcome. Happy to help.

Viewing 4 posts - 1 through 3 (of 3 total)

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