Reputation: 111
I was trying to load an image on a <asp:image>
control.
The thing is that the paths of the images are saved in the database, and some of the image names contain white spaces. For example "Image name number 2.jpg".
When I'm setting the ImageUrl attribute for the asp control, it can be assigned without any trouble, but when loaded in html the url is displayed as seen below:
"C:\..\..\Image%20name%20number%202.jpg"
Because of those "%20" it can't find the picture so it won't show.
What can I do to solve this?
Upvotes: 0
Views: 241
Reputation: 17381
The %20
part is actually the space character. You can easily remove it by passing the URL to decodeURI()
in javascript:
//fileName = "C:....\Image%20name%20number%202.jpg"
var fileName = decodeURI( fileName );
//fileName = "C:....\Image name number 2.jpg"
You can read more about it here: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/decodeURI
The opposite of decodeURI()
is encodeURI()
:
//fileName = "C:....\Image name number 2.jpg"
var fileName = encodeURI( fileName );
//fileName = "C:....\Image%20name%20number%202.jpg"
You can read more about it here: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/encodeURI
Upvotes: 1
Reputation: 18142
The %20
is expected to replace a space
whenever a string is represented as a URI.
These %20
s should not be causing you an issue, check your path.
For more information on this look into URL Encoding and Decoding: http://msdn.microsoft.com/en-us/library/zttxte6w.aspx http://msdn.microsoft.com/en-us/library/6196h3wt.aspx
Upvotes: 0