如何使用 MVC3 读取上传的文件?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Excel;
using System.Data;
namespace QuimizaReportes.Controllers
{
public class UploadController : Controller
{
public ActionResult Index()
{
//stream is supposed to be the excel file object.
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();
while (excelReader.Read())
{
}
excelReader.Close();
return View();
}
}
}
我应该让用户上传文件并从中读取,然后显示一条确认消息,表明该文件已保存。问题是:我怎样才能“获取”该流?有什么建议吗?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Excel;
using System.Data;
namespace QuimizaReportes.Controllers
{
public class UploadController : Controller
{
public ActionResult Index()
{
//stream is supposed to be the excel file object.
IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
excelReader.IsFirstRowAsColumnNames = true;
DataSet result = excelReader.AsDataSet();
while (excelReader.Read())
{
}
excelReader.Close();
return View();
}
}
}
I'm supposed to let users upload the file and read from it, then display a confirmation message that it has been saved. The question is: How can I 'get' that stream? Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这能解决问题吗?
与类似的东西结合使用:
Would this do the trick?
In conjunction with something like: