Cast HttpPostedFileBase to Stream

Dennis picture Dennis · Sep 7, 2017 · Viewed 7.4k times · Source

I'm working on an ASP.NET MVC project in in C#, trying to get upload a document from a form to my database. I'm currently in my controller where I have imported the file as HttpPostedFileBase, and it has to be converted to type Stream. How could I achieve this?

Thanks in advance!

HttpPostedFileBase document = form.DocumentFile;

Stream documentConverted = ?;

Answer

Dennis picture Dennis · Sep 7, 2017
var document = form.DocumentFile;
Stream documentConverted = document.InputStream;

Got it! I have to use .Inputstream to convert it directly.