locked
webClient.DownloadData | Error | The remote server returned an error: (404) Not Found. RRS feed

  • Question

  • Hi,

    I need help...

    I have a website hosted on IIS 6 and made it Direcotry Browsing checkbox checked in properties by rightclicking on website in IIS.

    Now in a perticular folder I have many .tiff files which I can download via WebClient.DownloadData method but if any filename has '#' character in its name then it throws the error "The remote server returned an error (404) Not Found."

     

    I also checked that when I browsed that directory in internet explorere it listed all files and on clicking the file having '#' character in its name open an alert to ask to download or Open, but when I request full url having filename( the # character in it) it does not open and says Page can not be found.

     

    Please help me..

     

    Monday, August 22, 2011 2:17 PM

Answers

  • Oh.. It is resolved.

    Thanks Andreas I followed it and I just encode my file name and it is now downloading the data.

     

    Thank you again..


    Wednesday, August 24, 2011 1:51 PM

All replies

  • You probably have to Url encode the filename.

    http://localhost/file#10.tiff must be http://localhost/file%2310.tiff

    You can use the UrlEncode method from HttpServerUtility

    http://msdn.microsoft.com/en-us/library/zttxte6w.aspx

     

    Monday, August 22, 2011 2:23 PM
  • Thanks Andreas for quick reply.

     

    I encoded the url but then it throws the error "could not find the file " .

     

    Monday, August 22, 2011 2:40 PM
  • Use a tool like fiddler to examine the request from webbrowser and the one from your application.

    http://www.fiddler2.com/fiddler2/

    If it works from webbrowser there is some difference still in the request.

    Monday, August 22, 2011 2:54 PM
  • Thanks Andreas,

    I sea that..

    Tuesday, August 23, 2011 1:18 PM
  • Did you find the problem? What was it?
    Tuesday, August 23, 2011 1:39 PM
  • No, Actually I have not worked with fiddler before, so I am in the way to see the problem.


    Tuesday, August 23, 2011 3:41 PM
  • Try this on one of the files for test, rename # to something else like Q....  see if that is root cause.

     

    P.S. If you browser to this folder in IE9 or IE8 and click on the file what happens?


    JP

    Tuesday, August 23, 2011 6:50 PM
  • Thanks ImFeelingGood

    I already checked that if I changed file name with any other character( I used @) other that # then it works fine. But my main problem is that I cant change the file name

    Wednesday, August 24, 2011 8:49 AM
  • With urlencoding I really expected it to work? Have you looked at the traffic using fiddler yet? Can you post the relevant code used to get the file?

    Wednesday, August 24, 2011 9:15 AM
  • Andreas,

     

    below are the code I am using

     

    System.Net.WebClient o = new System.Net.WebClient();
    byte[] arr = o.DownloadData("http://10.0.0.173/images/NewTest/1/admin_1782_22082011043441219159400#0.tif");

     

    and it throws the error  "page can not found".

     

    I have hosted the images folder on IIS 6.0 which have folder named "NewTest" and NewTest have folder named "1" and in 1 the file is admin_1782_22082011043441219159400#0.tif

    Wednesday, August 24, 2011 12:02 PM
  • You didn't try to URL encode it?

    System.Net.WebClient o = new System.Net.WebClient();
    byte[] arr = o.DownloadData(
    	System.Web.HttpUtility.UrlEncode(http://10.0.0.173/images/NewTest/1/admin_1782_22082011043441219159400#0.tif));
    
    you need to add reference to System.Web.dll if you haven't already
    Wednesday, August 24, 2011 12:20 PM
  • Andreas,

     

    I tried it but it thrown below error

     

    Could not find file 'E:\Rajan\EMSVSSSplit\AutomationManagerService\TestAutomationWindowSe\TestAutomationWindowSe\bin\Debug\http%3a%2f%2f10.0.0.67%2fimages%2fNewTest%2f1%2fadmin_3791_1808201106355597941150%230.tif'.

     

    I am using the code in my window form application and thus it is showing the first path of my running window form application and then http location.

     

     

    Wednesday, August 24, 2011 1:01 PM
  • You probably have to Url encode the filename.

    http://localhost/file#10.tiff must be http://localhost/file%2310.tiff

    You can use the UrlEncode method from HttpServerUtility

    http://msdn.microsoft.com/en-us/library/zttxte6w.aspx

     


    You didn't try this?

    System.Net.WebClient o = new System.Net.WebClient();
    byte[] arr = o.DownloadData("http://10.0.0.173/images/NewTest/1/admin_1782_22082011043441219159400%230.tif");

    Wednesday, August 24, 2011 1:44 PM
  • Oh.. It is resolved.

    Thanks Andreas I followed it and I just encode my file name and it is now downloading the data.

     

    Thank you again..


    Wednesday, August 24, 2011 1:51 PM
  • Perfect! Happy downloading! :)

    Wednesday, August 24, 2011 2:04 PM