0
嗨我需要編寫一個程序來存儲數據庫中的文件路徑,並將.doc文件存儲在一個新的文件位置下的文件名相同的名稱。我不知道如何爲它編寫代碼。文件上傳mvc 4 web應用程序到服務器無模式
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/SaveDoc/"), fileName);
file.SaveAs(path); }
return RedirectToAction("UploadDocument");
}
}
觀點::
@using (Html.BeginForm("Upload", "Upload", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="FileUpload" />
<input type="submit" name="Submit" id="Submit" value="Upload" /> }
請參考[動態創建目錄並將圖像保存到文件夾中](http://www.c-sharpcorner.com/blogs/create-directory-dynamically-and-save-image-to-folder-in-asp- net1) –
我使用Razor引擎,我相信.asp不會被支持,你能否以另一種方式幫助我(jqwidgets,boostrap,jquery等) – Cyborgsri
你寫的程序是存儲文件的基本和正確的程序 –