locked
WebClient -> Illegal characters in path. RRS feed

  • Question

  • Hi,

    I'm trying to download the following a image

    "http://lacoste.scene7.com/is/image/lacoste/10_CH5564-00_166_20?$detail$"

    with WebClient but I get the following exception:

     Illegal characters in path.

    Browsers don't have a problem with that URL and i don't see any illegal chars there...

    Cheers,
    Stefan


    Sunday, May 5, 2013 9:35 PM

Answers

  •  WebClient webClient = new WebClient();
     webClient.DownloadFile(strUri, filename);

    strUri = "http://lacoste.scene7.com/is/image/lacoste/10_CH5564-00_166_20?$detail$"

    dir = "C:\\websites\\dnndev.me\\DesktopModules\\TrendleyDNNModule\\Images"


    It is still not clear if filename is valid. Try an experiment with explicit paths:

    using (WebClient wc = new WebClient())
    {
        wc.DownloadFile("http://lacoste.scene7.com/is/image/lacoste/10_CH5564-00_166_20?$detail$", @"D:\test.jpg");
    }

    Does it work?

    • Proposed as answer by JohnWein Monday, May 6, 2013 12:31 PM
    • Marked as answer by My.self Monday, May 6, 2013 1:08 PM
    Monday, May 6, 2013 12:10 PM
  • "Does it work?"

    Yes!  Works fine.  Ignore my other posts on this thread. 

    Might take awhile to download all 5,000,000: 

    5000000*40000 = 2 * 10 ^ 11 = 200 GB.

    • Marked as answer by My.self Monday, May 6, 2013 1:08 PM
    Monday, May 6, 2013 12:29 PM

All replies

  • The WebClient can't run scripts.  It needs an actual physical entity to download, like a file, a string or byte[].
    Monday, May 6, 2013 12:20 AM
  • [...] I get the following exception:

     Illegal characters in path.

    If you are trying to use DownloadFile, then show how you did specify the file’s path. Probably it is incorrect. Show some details.

    Monday, May 6, 2013 6:39 AM
  •  WebClient webClient = new WebClient();
     webClient.DownloadFile(strUri, filename);

    strUri = "http://lacoste.scene7.com/is/image/lacoste/10_CH5564-00_166_20?$detail$"

    dir = "C:\\websites\\dnndev.me\\DesktopModules\\TrendleyDNNModule\\Images"

    Monday, May 6, 2013 9:10 AM
  • also tried this:

    either this: -> strUri = Uri.EscapeUriString(strUri);
    or this: -> strUri = HttpUtility.UrlEncode(strUri);
    
    WebClient webClient = new WebClient();
    webClient.DownloadFile(strUri, filename);

    Monday, May 6, 2013 9:23 AM
  • You need a Uri to an actual physical entity, not a script.  You're not allowed direct access to the image shown by "http://lacoste.scene7.com/is/image/lacoste/10_CH5564-00_166_20?$detail$"

    Use the right context menu and Save picture as ...

    Monday, May 6, 2013 9:26 AM
  • Right context menu?
    Save picture as??

    Can you please provide some code that shows how to do that please.

    The code pasted above is just a snipped of a CSC-Import. I need to import 5.000.000 products and automatically download the corresponding image to it...

    Monday, May 6, 2013 9:32 AM
  • "Right context menu?
    Save picture as??

    Can you please provide some code that shows how to do that please."

    I don't have any code.  Study the source of the page in your browser.

    "The code pasted above is just a snipped of a CSC-Import. I need to import 5.000.000 products and automatically download the corresponding image to it..."

    You should contact the site's webmaster to obtain direct access to the images.

    Monday, May 6, 2013 11:18 AM
  •  WebClient webClient = new WebClient();
     webClient.DownloadFile(strUri, filename);

    strUri = "http://lacoste.scene7.com/is/image/lacoste/10_CH5564-00_166_20?$detail$"

    dir = "C:\\websites\\dnndev.me\\DesktopModules\\TrendleyDNNModule\\Images"


    It is still not clear if filename is valid. Try an experiment with explicit paths:

    using (WebClient wc = new WebClient())
    {
        wc.DownloadFile("http://lacoste.scene7.com/is/image/lacoste/10_CH5564-00_166_20?$detail$", @"D:\test.jpg");
    }

    Does it work?

    • Proposed as answer by JohnWein Monday, May 6, 2013 12:31 PM
    • Marked as answer by My.self Monday, May 6, 2013 1:08 PM
    Monday, May 6, 2013 12:10 PM
  • "Does it work?"

    Yes!  Works fine.  Ignore my other posts on this thread. 

    Might take awhile to download all 5,000,000: 

    5000000*40000 = 2 * 10 ^ 11 = 200 GB.

    • Marked as answer by My.self Monday, May 6, 2013 1:08 PM
    Monday, May 6, 2013 12:29 PM
  • Omg,
    I was staring at the wrong side all the time :( 

    My problem was that I used "10_CH5564-00_166_20?$detail$" as my filename.

    And I asumed that the problem is on the URL

    I have to import products from CSV-Files and each of them come from a different publisher.

    Nearly all publisher use this url format:

    http://media.douglas.de//382745/300_0/MAC-Lippenstift-Lipstick.jpg

    so I can take "MAC-Lippenstift-Lipstick.jpg" as my filename.

    It is clear that this strategy is not working for lacoste shop...

    Many thanks!

    Cheers,

    Stefan

    Monday, May 6, 2013 1:08 PM