Rizwan Khan
Rizwan Khan

Reputation: 401

how do i extract a file name from encoded/rewrite url in C#

how do i extract a file name from encoded/rewrite url in C# like http://download.mozilla.org/?product=firefox-8.0b5&os=win&lang=en-US

Uri uri = new Uri(textBox1.Text);
string filename = Path.GetFileName(uri.LocalPath);

above code is returning the blank value.

Upvotes: 2

Views: 243

Answers (3)

Joshua Marble
Joshua Marble

Reputation: 560

Since the question has been clarified, try this as an answer.

string url = "http://download.mozilla.org/?product=firefox-8.0b5&os=win&lang=en-US";
WebRequest req = WebRequest.Create(url);
var res = req.GetResponse();
var fileUri = res.ResponseUri;

Returns fileUri similar to:

http://pv-mirror02.mozilla.org/pub/mozilla.org/firefox/releases/8.0b5/win32/en-US/Firefox%20Setup%208.0b5.exe

Upvotes: 3

Joshua Marble
Joshua Marble

Reputation: 560

I'm not sure how useful this output is, but:

string url = "http://download.mozilla.org/?product=firefox-8.0b5&os=win&lang=en-US";
string name = Path.GetFileName(url);

Returns

"?product=firefox-8.0b5&os=win&lang=en-US"

Upvotes: -1

Haedrian
Haedrian

Reputation: 4328

I'd personally put it into a web browser control, wait for it to load and when its ready I grab the url from the web browser control.

If I understood you correctly.

Upvotes: 0

Related Questions