Created
December 29, 2011 10:05
-
-
Save allen501pc/1533307 to your computer and use it in GitHub Desktop.
ASP.NET- 從web.config中取得檔案上傳下載目錄設定
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 要使用 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