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 FileStream.
I wrote:
public void Test(HttpPostedFileBase postedFile) {
FileStream fileStream = (FileStream)(postedFile.InputStream); // throw exception
FileStream anotherFileStream = postedFile.InputStream as FileStream; // null
}
I tried also
public void Test(HttpPostedFileBase postedFile) {
Stream stream = postedFile.InputStream as Stream;
FileStream myFile = (FileStream)stream;
}
But no success.
Why at postedFile.InputStream
comes HttpInputStream
type ?
And how could I solve this issue ?
Thanks
public byte[] LoadUploadedFile(HttpPostedFileBase uploadedFile)
{
var buf = new byte[uploadedFile.InputStream.Length];
uploadedFile.InputStream.Read(buf, 0, (int)uploadedFile.InputStream.Length);
return buf;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With