[英]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.