Cast HttpPostedFileBase to Stream

11.7k views Asked by At

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 = ?;
1

There are 1 answers

1
Nuss9 On
var document = form.DocumentFile;
Stream documentConverted = document.InputStream;

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