简体   繁体   中英

Copy file from one path to another

A am fetching a file name and file path from the database as described below:

        msSQL = " select file_name,file_path FROM myTable where file_id='F012'"
        Dim Reader = myCommonFun.GetDataReader(msSQL)
        Dim file_path As String = Nothing
        If Reader.HasRows = True Then
            Reader.Read()
            Dim file_Name as string = Reader.Item("file_name").ToString
            Dim file_path = Reader.Item("file_path").ToString
        End If

Now what i need is that i want to take the file in the path returned by the query and copy the same file to another location. for that am using the snippet as :

Dim destinationFile as string = Server.MapPath("../uploaded/" & file_Name)
File.Copy(file_path , destinationFile, True)

but it wont result as expected, what am doing wrong? how can i achieve the target?

Updates

  • in File.Copy(file_path , destinationFile, True)
  • file_path : D:\\new\\data\\me.doc
  • destinationFile : D:\\web\\mypro\\uploaded\\me.doc

You should combine file_path with file_Name with extension Try below code

Dim destinationFile as string = Server.MapPath("../uploaded/" & file_Name)
File.Copy(file_path , destinationFile, True)

Change to

Dim destinationFile as string = Server.MapPath("../uploaded/" & file_Name)
file_path =file_path &"\\"& file_Name
File.Copy(file_path , destinationFile, True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM