ashkufaraz
ashkufaraz

Reputation: 5307

get extension of file(edit)

i want get extension file of url .

for example get extension http://www.iranfairco.com/download-file/02912bb889cb24. if extension this file is gif.

EDIT:

for example this url "http://www.online-convert.com/result/d8b423c3cbc05000cc52ce7015873e72"

Please help me how can get extension of this url?

Upvotes: 5

Views: 7971

Answers (5)

Hans Kesting
Hans Kesting

Reputation: 39338

Why does Path.GetExtension not work for you?

EDIT
Ah, so your url doesn't specify the extension you are after. That means anything could be behind it.

Just by inspecting the string value of the url, you can't see what will behind it. Your (second) example point (ultimately) to a .gif file, but it could also have been a .jpg, .doc (or even .exe).

You will need to do a webrequest to see what you get back. Usually you could try a HEAD to get just the headers (and inspect the content type), but I don't think that will work here. Try Fiddler to see what you get back, then you can refine your question.

Upvotes: 10

4b0
4b0

Reputation: 22321

try this

string path = @"http://www.iranfairco.com/download-file/02912bb889cb24.gif";
 string e = Path.GetExtension(path );

Upvotes: 4

Curtis
Curtis

Reputation: 103428

This URL appears to perhaps be linking to a page which will have a download for a file.

The 02912bb889cb24 is perhaps a database reference to that file.

Therefore without access to any API for this system, I don't think its possible at all to work out the file extension for the file accessed via this URL

Upvotes: 1

musefan
musefan

Reputation: 48455

Check out here:

http://www.java2s.com/Code/CSharp/Network/GetHTTPResponseheaders.htm

You will be interested in the response.ContentType which should give you something like "image/gif" for a gif image

Upvotes: 6

Rob
Rob

Reputation: 4947

You can just split the string on char '.' and get the last string in the returned array..

Upvotes: 0

Related Questions