[英]Copy file from one path to another
一个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
现在,我需要的是将文件放在查询返回的路径中,并将同一文件复制到另一个位置。 为此使用以下代码段:
Dim destinationFile as string = Server.MapPath("../uploaded/" & file_Name)
File.Copy(file_path , destinationFile, True)
但是它不会产生预期的结果,这是怎么了? 我怎样才能达到目标?
更新
File.Copy(file_path , destinationFile, True)
D:\\new\\data\\me.doc
D:\\web\\mypro\\uploaded\\me.doc
您应该将file_path与file_Name与扩展名结合使用尝试以下代码
Dim destinationFile as string = Server.MapPath("../uploaded/" & file_Name)
File.Copy(file_path , destinationFile, True)
改成
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.