Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save allen501pc/1533307 to your computer and use it in GitHub Desktop.
Save allen501pc/1533307 to your computer and use it in GitHub Desktop.
ASP.NET- 從web.config中取得檔案上傳下載目錄設定
/* 要使用 ConfigurationManager,需引入System.Configuration 這個namespace */
using System.Configuration;
/* 程式碼區 */
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
//檢查是否有檔案上傳,有的話存檔
if (file !=null && file.ContentLength > 0)
{
// 取得檔案放置的目錄
string savedName = ConfigurationManager.AppSettings["FileDirectory"] + file.FileName;
// 存放檔案
file.SaveAs(savedName);
}
return View();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment