I want to know that for make sure that the file that will be download from my script will have the extension I want.
The file will not be at URLs like:
h
Some have suggested requesting the file from the url and checking the headers. That's overkill for something so simple in my opinion so...
Heringers answer fails if parameters are present on the url, the solution is simple just Split
on the query string char ?
.
string url = @"http://example.com/file.jpg";
string ext = System.IO.Path.GetExtension(url.Split('?')[0]);