Asp.net mvc 处理上载的文件而不保存?
我正在使用以下代码上传一个文件Asp.net mvc 处理上载的文件而不保存?,asp.net-mvc,asp.net-mvc-3,Asp.net Mvc,Asp.net Mvc 3,我正在使用以下代码上传一个文件 [HttpPost] public ActionResult ImportDeleteCourse(ImportFromExcel model) { var excelFile = model.ExcelFile; if (ModelState.IsValid) { OrganisationServices services = new OrganisationServices(); string filePath = Path.C
[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。该属性看起来很有前途。您应该能够使用它并将数据保存到您需要的任何其他流。当然可以。正如Patko所建议的,InputStream属性可以用于另一个流。例如,我这样做是为了上传一个xml文档,以便与LINQ to xml一起使用:
XDocument XmlDoc = XDocument.Load(new StreamReader(viewmodel.FileUpload.InputStream))
干杯,
Chris我是.NET新手-我不知道怎么做。这个ImportFromExcel类是什么?你能展示它的方法,字段,任何能提供线索的东西吗?尝试使用Reflector或在Visual Studio中列出它们