locked
get file name from url RRS feed

  • Question

  • User-1999101176 posted

    hi,

    i want to get only file name from url. suppose i've a url http://www.sitename.com/page.aspx?pid=4&uid=10

    and i want to get only page.aspx

    is it possible in vb.net?

    Please help

    Sunday, October 16, 2011 12:14 PM

Answers

  • User1927273029 posted

    Hi,

    to get url of the curret page you can write

    Request.Url.AbsoluteUri

    Uri uri = new Uri(Request.Url.AbsoluteUri);
    string filename = Path.GetFileName(uri.LocalPath);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 16, 2011 12:42 PM

All replies

  • User1927273029 posted

    Hi,

    Try following

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

    Hope it works
    Sunday, October 16, 2011 12:20 PM
  • User1927273029 posted

    Hi,

    Try following

    Uri uri = new Uri(hreflink);
    string filename = Path.GetFileName(uri.LocalPath);
    Sunday, October 16, 2011 12:20 PM
  • User-1999101176 posted

    Thanks jassi,

    will you please guide me how will i get url first? then will be able to get file name.

    please help

    Sunday, October 16, 2011 12:37 PM
  • User1927273029 posted

    Hi,

    to get url of the curret page you can write

    Request.Url.AbsoluteUri

    Uri uri = new Uri(Request.Url.AbsoluteUri);
    string filename = Path.GetFileName(uri.LocalPath);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, October 16, 2011 12:42 PM
  • User-1999101176 posted

    Thanks Jassi,

    It works. thanks alot.

    is it possible if we check some file name in web.config file?

    actually i want to check three file names. if file is not the same as these file name then go to my specified page.

    e.g

    if page name not equal to default.aspx go to myotherpage.aspx

     for now if we write some other name which is not exist, it gives error.

    so please help

    Sunday, October 16, 2011 12:51 PM