Books という名前のフォルダーにパスを含むファイルをアップロードするコードを次に示します。パスのみをデータベースに保存し、パスに基づいて Books フォルダーからファイルをフェッチします。以下は私のコードで、私はasp.net mvc 4とエンティティフレームワークを使用しています。
[HttpPost]
public ActionResult upload(HttpPostedFileBase file)
{
//verify that the file is selected and not empty
if (file != null && file.ContentLength > 0)
{
//getting the name of the file
var fileName = Path.GetFileName(file.FileName);
//store file in the Books folder
var path = Path.Combine(Server.MapPath("~/BOOKS"), fileName);
file.SaveAs(path);
}
return View();
}