Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

hello

i want to copy an ms access database file (.mdb) from a dir to another, simple, but my program throws an excpetion NotSupportedException saying "Given path's format is not supported", how can i copy my file??, here's my code:

 

           Dim path As String = ""
'target filename will contain today's date
           Dim hoy As String = Today.ToString
           hoy = hoy.Replace("\", "-")

           Dim path1 As String = selPath.SelectedPath + "\udm_" + hoy + "_"
           Dim ext As String = ".mdb"
           Dim num As Integer = 1
'generate target path 
          path = path1 + num.ToString + ext
'check if not exists, else increment the number
           While File.Exists(path)
               num = num + 1
               path = path1 + num.ToString + ext
           End While

           Dim source As String = Me.path + "db\db.mdb"

'exception thrown around the next lines
           Dim fs As FileStream = File.Create(path)
           fs.Close()
           File.Copy(source, path)

 

thanks for your help

Posted

To combine paths you should use Path.Combine(). You aren't checking the path length so see if it exceeds the limit of length, you aren't checking for invalid characters, you aren't checking that the destination directory exists. If it ever worked it'd be through luck not skill.

You need to validate your data. I think you're probably ending up with an illegal character from the date.ToString() but you'll find that out for yourself when you step through it.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...