Cast HttpPostedFileBase to Stream
Asked Answered
N

1

6

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 = ?;
Nepean answered 7/9, 2017 at 17:54 Comment(0)
N
13
var document = form.DocumentFile;
Stream documentConverted = document.InputStream;

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

Nepean answered 7/9, 2017 at 18:4 Comment(1)
Thanks @Dennis . it saved my time a lot.Cooperman

© 2022 - 2024 — McMap. All rights reserved.