【发布时间】:2011-02-25 00:09:25
【问题描述】:
这是我的控制器:
[HttpPost]
public ActionResult Index(HttpPostedFileBase excelFile)
{
/*Somewhere here, I have to save the uploaded file.*/
var fileName = string.Format("{0}\\{1}", Directory.GetCurrentDirectory(), excelFile.FileName);
var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", fileName);
var adapter = new OleDbDataAdapter("SELECT * FROM [workSheetNameHere$]", connectionString);
var ds = new DataSet();
adapter.Fill(ds, "results");
DataTable data = ds.Tables["results"];
return View();
}
【问题讨论】:
-
你到底想保存什么到磁盘?
-
excelFile 是上传到网站的文件。 .xlsx 文件。我需要将该文件永久保存到硬盘驱动器。我猜使用 .InputStream 属性?但我对如何做到这一点感到困惑。
-
如果您只是想知道如何保存 excelFile,我们不需要与数据库对话的其余代码 - 这很令人困惑。只需提供最少量的代码。