好吧,我在網上找到這個文件來上傳一些文件。asp文件上傳控件,哪一個應該用?
if (FileUpload1.HasFile)
{
//create the path to save the file to
string fileName = Path.Combine(@"E:\Project\Folders", FileUpload1.FileName);
//save the file to our local path
FileUpload1.SaveAs(fileName);
}
這
//check to make sure a file is selected
if (FileUpload1.HasFile)
{
//create the path to save the file to
string fileName = Path.Combine(Server.MapPath("~/Files"), FileUpload1.FileName);
//save the file to our local path
FileUpload1.SaveAs(fileName);
}
什麼區別,使用哪一個?我感到困惑。順便說一下,如果我可以在數據庫中存儲文件路徑,並且下次當我想刪除或查看該文件時,如何檢索該文件?所以說,首先我添加一條記錄到數據庫並上傳一個.doc文件/ excel文件,下一次當我想要編輯該記錄時,我想要檢索上傳的文件並在UI中顯示它。謝謝。
使用第二個,因爲它會將相對或虛擬路徑轉換爲真實路徑本身。 .u應該從db獲得路徑並使用它來解析路徑,就像你存儲的一樣,並對它進行操作刪除等等,以顯示url =「〜/ Files/yourfilename」 – qwr
如果你已經知道你的文件夾是:E :\ ftproot \ sales那麼你不需要使用Server.MapPath,如果你只有一個像〜/ folder/folder1這樣的相對虛擬路徑,並且你想知道磁盤中的真實路徑,則需要最後一個路徑... – karthi