简体   繁体   English

将文件从一个路径复制到另一路径

[英]Copy file from one path to another

A am fetching a file name and file path from the database as described below: 一个am从数据库中获取文件名和文件路径,如下所述:

        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.Copy(file_path , destinationFile, True)
  • file_path : D:\\new\\data\\me.doc file_path: D:\\new\\data\\me.doc
  • destinationFile : D:\\web\\mypro\\uploaded\\me.doc destinationFile: D:\\web\\mypro\\uploaded\\me.doc

You should combine file_path with file_Name with extension Try below code 您应该将file_path与file_Name与扩展名结合使用尝试以下代码

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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