none
Uri replaces %20 with space

    Question

  • Hello,

    My problem is that I have a url as a string:

            http://server/foldername%20with%20space/picture.jpg. 

    Then I have to make a Uri from it in order to pass as a parameter to the WebClient.But the Uri converts it to   

            http://server/foldername with space/picture.jpg.

    And of course I cannot download the picture using this Uri.
     

    Any idea how to resolve this?

    Thank you in advance,

    Kinga 

    Friday, April 18, 2008 4:08 AM

Answers

  • Well, in Beta2, WebClient.OpenReadAsync is likely to change to use a string as the parameter to be consistent with desktop CLR. That should be able to solve your problem. But I can't assure you that until we release Beta2.

    Thursday, April 24, 2008 3:37 AM

All replies

  • Kinga,

    I tried this HtmlPage.Window.Navigate(new Uri("http://projectsilverlight.blogspot.com/search?q=deep%20zoom"), "_newWindow"); and it worked beautifully. A new window got invoked with the following URL: http://projectsilverlight.blogspot.com/search?q=deep%20zoom (retained the %20).

    This worked fine as well:
                String str = "http://projectsilverlight.blogspot.com/search?q=deep%20zoom";
                HtmlPage.Window.Navigate(new Uri(str), "_newWindow"); 

    Do you have a specific example to illustrate your problem?

    Hope this helps!

    Wilfred Pinto
    http://projectsilverlight.blogspot.com
     

    Friday, April 18, 2008 2:15 PM
  • Hi,

    Thank you for your reply.

    I tried your example, it worked. One thing that I noticed is that you navigate to that Uri it doesn't matter if it replaces the spaces or not because the browser will replace it anyway.But I am using the Uri for downloading with Webclient.
    In case of your example I have also seen that the Uri replaces the %20 with space..
    I can show my case of course:

    url="http://server/piclist/folder%20folder/screen1.jpg"
    The server is a local Sharepoint server..
    Uri u = new Uri(url);
     webclient.OpenReadAsync(u);
    I have tried setting the UriKind to Absolute but there was no difference in the result Uri.

    Any idea?

     

    Friday, April 18, 2008 3:17 PM
  • Kinga,

    You are absolutely right! The Uri object does convert %20 to a space.

    As you mentioned, the reason it is working in the browser is because the browser converts a space to %20.

    If there is no workaround for this, it would definitely be a showstopper. You should definitely post this in the 'Report a Bug' section if you do not get a solution soon.

    Wilfred
     

    Friday, April 18, 2008 6:15 PM
  • Hello, this is by design. Uri's constructor will decode the uriString parameter. This behavior is consistent with desktop .NET. But this should not introduce any problems. I haven't tried SharePoint. But I tried a WCF REST service. I used this url with a WebClient:

    http://localhost:25784/URIEncoding_Web/Service%20with%20space.svc/DoWork

    It is replaced by:

    http://localhost:25784/URIEncoding_Web/Service with space.svc/DoWork

    But the runtime will point to the correct address, and I got the correct result.

    Monday, April 21, 2008 1:00 AM
  •  Hi,

    Thank you.

    I got your point with the consistency.

    I am sure that this is not working for Sharepoint. There is no problem with calling the service from Sharepoint, that doesn't have spaces in it. The problem is when downloading something from a folder or list which has spaces.

    Isn't there any setting for the Uri so I can keep the %20-s?

    Or another solution would be for me if I could use the DownloadProgressChanged eventhandler of an Image. But it seemed I cannot. Why?

     

    Kinga 

    Monday, April 21, 2008 2:22 AM
  • Well, in Beta2, WebClient.OpenReadAsync is likely to change to use a string as the parameter to be consistent with desktop CLR. That should be able to solve your problem. But I can't assure you that until we release Beta2.

    Thursday, April 24, 2008 3:37 AM