SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


VB ScriptTask in SSIS


VB ScriptTask in SSIS

Author
Message
lduvall
lduvall
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1154 Visits: 396
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
kl25
kl25
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1164 Visits: 1875
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.
lduvall
lduvall
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1154 Visits: 396
That worked perfectly and was exactly what I needed.
Thanks so much!!
kl25
kl25
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1164 Visits: 1875
You're quite welcome. Happy to help.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search