Results 1 to 4 of 4

Thread: How to get folder name from url

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Posts
    91

    How to get folder name from url

    hi

    How to get folder name from url

    like http:\\vinaykumar\Test\hllo.jpg


    From this i need to get FolderName:Test

    Please help me in this regard

    Thanks
    Vinay

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: How to get folder name from url

    Code:
    string url = @"http:\\vinaykumar\Test\hllo.jpg";
    string[] tmp = url.Split('\\');
    MessageBox.Show(tmp[3]);

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Posts
    91

    Re: How to get folder name from url

    Thnk u


    got it


    Thanks again
    Regards
    Vinay

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to get folder name from url

    You use the System.IO.Path class to manipulate file and folder paths:
    C# Code:
    1. string path = @"http://vinaykumar/Test/hllo.jpg";
    2. string folder = Path.GetFileName(Path.GetDirectoryName(path));
    Note that the names there may seem a little confusing but if you understand what each method does then it's clear. GetDirectoryName get's the fully qualified path less the part after the last delimiter, which may be a file or folder name. Thus GetDirectoryName returns @"http://vinaykumar/Test". GetFileName does the opposite: it gets ONLY the part after the last delimiter, which may or may not actually be a file name.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width