1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to retrieve filename from a weird download url ?

Discussion in 'C, C++, C#' started by foozoor, Dec 2, 2014.

  1. foozoor

    foozoor Newbie

    Joined:
    Nov 16, 2014
    Messages:
    11
    Likes Received:
    0
    Previously when I needed to download a file, I get the filename from the url itself.

    But some weird urls (sorry I can't post urls here) don't have the filename in its url.
    Some urls don't provide content disposition too!

    What's the best way to retrieve download original filename from any kind of url with c# ?
     
  2. Orianbeter

    Orianbeter Newbie

    Joined:
    Nov 9, 2014
    Messages:
    11
    Likes Received:
    4
    if the server doesnt give you that infomation, maybe u can grab it out of ur downloader eg by checking ind your dl directory for .part files? would be my aproach to this problem...
     
  3. boberbrian

    boberbrian Registered Member

    Joined:
    Jul 6, 2013
    Messages:
    71
    Likes Received:
    22
    The HTTP protocol isn't saying anything about filenames.
    This means that there is no standard for this, and the server may or may not specify the filename.

    If you can retrieve if from the URL - good for you!
    If not - then you are just stuck, and there is no way to retrieve it.
    You can guess it or generate it on your own.
     
  4. foozoor

    foozoor Newbie

    Joined:
    Nov 16, 2014
    Messages:
    11
    Likes Received:
    0
    How web browsers do so ?
    I need to download a file from a short url that redirect to the file download.
    I need to retrieve the true filename because the file change its extension sometimes.
    Today it's an .tar.gz archive but yesterday it was a .7z archive.

    Furthermore, it would be great to have a download function that download and get filename from any url.
     
  5. rawr00

    rawr00 Newbie

    Joined:
    Feb 24, 2014
    Messages:
    7
    Likes Received:
    3
    Did you check out the requests in a traffic viewer? I can't help much without the URL, or at least some more info.