Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Best way to get FileName and DirectoryName of a URL?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252

    Resolved [RESOLVED] [2005] Best way to get FileName and DirectoryName of a URL?

    Hi All,

    I was messing with this yesterday and today morning to get the FileName and URL without the FileName. Apparently Path.GetFileName and Path.DirectoryName only works for Local paths and not for URLs.

    I was wondering what would be the best way to extract these information so that from a URL like http://wmwiki.com/downloads/itsfv/it....9.1-setup.zip I can get
    FileName: itsfv-4.0.9.1-setup.zip and DirectoryName: http://wmwiki.com/downloads/itsfv

    Thanks,
    McoreD

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

    Re: [2005] Best way to get FileName and DirectoryName of a URL?

    IO.Path will work with URLs but you'll have to adjust the result slightly.
    Attached Images Attached Images  
    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

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    252

    Re: [2005] Best way to get FileName and DirectoryName of a URL?

    Wow, it works mate.

    VB Code:
    1. MessageBox.Show(Path.GetDirectoryName(downloadUrl).Replace('\\', '/').Replace(":/", "://"));

    For some reason it didn't work last night and had an error in Console saying URI arent supported but that may be due to some other unfinished code I had last night. It works great today.

    Thanks!

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