我使用下面的代码处理上传的文件而不保存它?
[HttpPost]
public ActionResult ImportDeleteCourse(ImportFromExcel model)
{
var excelFile = model.ExcelFile;
if (ModelState.IsValid)
{
OrganisationServices services = new OrganisationServices();
string filePath = Path.Combine(HttpContext.Server.MapPath("../Uploads"),
Path.GetFileName(excelFile.FileName));
excelFile.SaveAs(filePath);
// ... snipped //
}
}
我并不真的需要做存储上传的Excel文件上传文件。无论如何,我可以在不保存的情况下处理它吗?
注:ImportFromExcel类不过是一个模型,这基本上是:
public class ImportFromExcel
{
[Required(ErrorMessage = "Please select an Excel file to upload.")]
[DisplayName("Excel File")]
public HttpPostedFileWrapper ExcelFile { get; set; }
}
最有趣的部分是,它封装了一个HttpPostedFileWrapper。
只是保存到的MemoryStream? – jakubmal 2011-06-01 10:05:11
我是.NET新手 - 我不知道该怎么做。 – Extrakun 2011-06-01 10:17:11
这是什么ImportFromExcel类?你能展示它的方法,领域,无论给出任何线索吗?尝试使用反射器http://reflector.red-gate.com/download.aspx或在Visual Studio中列出它们 – jakubmal 2011-06-01 10:20:20