Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get file type of request.files in asp.net

How to get file extension from the request.files collection in asp.net?

like image 856
Shyam s Avatar asked Feb 26 '11 08:02

Shyam s


2 Answers

I think this should do the trick:

foreach (HttpPostedFile file in Request.Files) {
    string extension = System.IO.Path.GetExtension(file.FileName);
}
like image 72
jevakallio Avatar answered Sep 24 '22 19:09

jevakallio


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.

like image 45
Marc Gravell Avatar answered Sep 23 '22 19:09

Marc Gravell