10 April 2007

Get File Name from URL (C#/.NET)

Posted by Mikhail Esteves under: C#; Tips .

To get the file name from a URL like http://www.thejackol.com/files/project.exe:

string URL = "http://www.thejackol.com/files/project.exe";
string FileName = URL.Substring(URL.LastIndexOf("/") + 1,
    (URL.Length - URL.LastIndexOf("/") - 1));

FileName will now contain project.exe



One Comment so far...

Tim Gaunt Says:

22 June 2007 at 10:09 pm.

Seeing as you’re not validating the end of the file name you can leave off the length param:

string FileName = URL.Substring(URL.LastIndexOf(”/”) + 1);

HTH

Tim

Leave a Reply

Browse

Photography

Projects

Pages

Calendar

April 2007
M T W T F S S
« Mar   May »
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Categories

www.flickr.com