我使用文件上传选项上传文件。我直接发送这个文件从View到控制器在POST方法like,
[HttpPost] public ActionResult Page2(FormCollection objCollection) { HttpPostedFileBase file = Request.Files[0]; }
解决方法
这可以使用httpPostedFileBase类返回HttpInputStreamObject根据指定的
here
请参考以下链接
http://msdn.microsoft.com/en-us/library/system.web.httprequest.inputstream.aspx]
希望这可以帮助
更新:
The stream that you get from your HTTP call is read-only sequential
(non-seekable) and the FileStream is read/write seekable. You will
need first to read the entire stream from the HTTP call into a byte
array,then create the FileStream from that array.
摘自here
// Read bytes from http input stream BinaryReader b = new BinaryReader(file.InputStream); byte[] binData = b.ReadBytes(file.InputStream.Length); string result = System.Text.Encoding.UTF8.GetString(binData);