簡體   English   中英

想要在實時服務器中上傳文件,而不是ASP.Net MVC中的App_Data文件夾

[英]Want to upload file in the live server other than App_Data folder in ASP.Net MVC

我需要在實時服務器的〜/ Images / Item文件夾中上傳圖像。 我可以在〜/ App_Data / Images文件夾中上載,沒有任何例外。 但是,當我嘗試在〜/ Images / Item中上載時,它給了我異常,並顯示消息"A generic error occurred in GDI+"

我已經搜索過,但是沒有找到適合我的解決方案。 任何形式的建議將不勝感激。

你可以做這樣的事情。 請確保該應用程序對此文件夾具有寫權限。

[HttpPost]
public ActionResult Index(HttpPostedFileBase file) {
 // Verify that the user selected a file
 if (file != null && file.ContentLength > 0) {
  // extract only the filename
  var fileName = Path.GetFileName(file.FileName);
  // store the file inside ~/App_Data/uploads folder
  var path = Path.Combine(Server.MapPath("~/Images/Item"), fileName);
  file.SaveAs(path);
 }

 return RedirectToAction("Index");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM