Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract file name from an Uri in C#? [duplicate]

Tags:

c#

uri

Possible Duplicate:
Get file name from URI string in C#

How to extract file name from an Uri in C#?

for instance, I have a Uri

"http://audacity.googlecode.com/files/audacity-win-2.0.exe"

but how to extract the file name

"audacity-win-2.0.exe"

and save it as a string?

Thank you,

Jerry

like image 794
Jerry Avatar asked Jun 28 '12 04:06

Jerry


2 Answers

How about

Path.GetFileName(string path);

In your case

Path.GetFileName(new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe").AbsolutePath);
like image 61
Nikhil Agrawal Avatar answered Sep 18 '22 14:09

Nikhil Agrawal


Path.GetFileName can do it...

        Uri u = new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe");
        Path.GetFileName(u.AbsolutePath);
like image 42
Michael Avatar answered Sep 20 '22 14:09

Michael