How to get file extension from the request.files collection in asp.net?
I think this should do the trick:
foreach (HttpPostedFile file in Request.Files) {
string extension = System.IO.Path.GetExtension(file.FileName);
}
Each HttpPostedFile
in Request.Files
has a FileName
that includes the extension; to get just the extension, use Path.GetExtension(file.FileName)
Note that using the content-type may be more reliable in many cases.
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