Unable to cast object of type 'System.Web.HttpInputStream' to type 'System.IO.FileStream' MVC 3

后端 未结 5 756
無奈伤痛
無奈伤痛 2021-02-19 06:37

I have met an issue regarding the casting type from HttpInputStream to FileStream.

How I did ?

I have a HttpPostedFileBase object and I want to have

5条回答
  •  青春惊慌失措
    2021-02-19 07:17

    You can use the .SaveAs method to save the file content. HttpInputSteam probably because it's uploaded through http [browser]

     postedFile.SaveAs("Full Path to file name");
    

    You can also use CopyTo

    FileStream f = new FileStream(fullPath, FileMode.CreateNew);
    postedFile.InputStream.CopyTo(f);
    f.Close();
    

提交回复
热议问题