0

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

J.S. Orris
  • 3,816
  • 8
  • 37
  • 78
  • 1
    your file has some illegal chars in it, doesnt it? `"...Dir3\FileName2/26/2015.xlsx"` – Ňɏssa Pøngjǣrdenlarp Feb 27 '15 at 01:58
  • oops...sorry about that..I noticed that earlier and took out the illegal characters....still saying file doesn't exist...Ill make the edit to the question – J.S. Orris Feb 27 '15 at 01:59
  • 1
    Maybe [a credentials issue](http://stackoverflow.com/questions/2352197/how-do-i-access-a-network-drive-through-the-usual-system-io-classes)? – sorrell Feb 27 '15 at 02:28
  • So...it wasn't working because I had the directory open in which the files existed. I closed the directory and reran and works now. In short...idiot move on my part ;) – J.S. Orris Feb 27 '15 at 02:32

0 Answers0