尝试从用户选择的文本文件中将文本读入内存
MODEL:
public HttpPostedFileBase File { get; set; }
查看
<form action="" method="post" enctype="multipart/form-data" id="MyForm">
@Html.TextBoxFor(m => m.File, new { type = "file" })
<input type="submit" name="btnSubmit" id="ProcessAll" value="Process All" />
</form>
控制器:
[HttpPost]
public ActionResult FileToFasta(F2FModel model)
{
//Need to read file to a string without uploading it
return View(model);
}
有什么想法?感谢
答案 0 :(得分:3)
new StreamReader(model.File.InputStream).ReadToEnd()
答案 1 :(得分:0)
使用System.IO命名空间。
var sw = new StreamReader(model.File.InputStream);
var text = sw.ReadToEnd();
sw.Close();