I am dynamically creating reports using an Excel Template for an SSIS Package. I am attempting to copy the Excel template and rename it using VB 2010 in Script Task object.
The following is my code:
Public Sub Main()
Dim sourcePath As String = "\\server\Dir1\Dir2\Dir3\FileName_TEMPLATE.xlsx"
Dim destPath As String = "\\server\Dir1\Dir2\Dir3\FileName" + CDate(Date.Today.Date).ToString("yyyyMMdd") + ".xlsx"
If File.Exists(destPath) = True Then
File.Delete(destPath) 'delete existing file'
File.Copy(sourcePath, destPath) 'copy template file and rename'
End If
Dts.TaskResult = ScriptResults.Success
End Sub
End Class
I changed If File.Exists(destPath) = True Then...
to If File.Exists(sourcePath) = True...
to see if the sourcePath
existed and then added a MessageBox("File doesn't exist")
in an ELSE
statement to so if even the source file exists and it is returning the MessageBox
stating
"File doesn't exist"
The Template file is there and I copied and pasted the address from Windows Explorer window to the sourcePath
string to ensure path accuracy.
The sourcePath
is on a different server.
The file is in the source path.
What am I doing wrong?
Thanks