ASP.Net MVC - Read File from HttpPostedFileBase without save

后端 未结 4 1365
醉酒成梦
醉酒成梦 2020-11-29 23:40

I am uploading the file by using file upload option. And i am directly send this file from View to Controller in POST method like,

    [HttpPost]
    public          


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 00:20

    A slight change to Thangamani Palanisamy answer, which allows the Binary reader to be disposed and corrects the input length issue in his comments.

    string result = string.Empty;
    
    using (BinaryReader b = new BinaryReader(file.InputStream))
    {
      byte[] binData = b.ReadBytes(file.ContentLength);
      result = System.Text.Encoding.UTF8.GetString(binData);
    }
    

提交回复
热议问题