I am displaying images from an URL using XML parsing and some images are displaying very well, but sometimes I get exception like
Illegal character in path at index 113: http://www.theblacksheeponline.com/party_img/thumbspps/12390867930_15951_186997180114_709920114_4296270_6115611_n[1].jpg
How to solve this problem, please provide some sample code...
You can simply use C# inbuilt function " Path. GetInvalidFileNameChars() " to check if there is invalid character in file name and remove it.
The "Illegal characters" exception means that the file path string you are passing to ReadXml is wrong: it is not a valid path. It may contain '?' , or ':' in the wrong place, or '*' for example.
To insert characters that are illegal in a string, use an escape character. An escape character is a backslash \ followed by the character you want to insert.
Special characters need escaping such as %5B
for [ and %5D
for ]
You can use the java.net.URLEncoder
to encode the URL as in
java.net.URLEncoderURLEncoder.encode(myurltoencode,"UTF-8");
This will not just fix the [ or ] but also other encoding issues
use this escape code for [ %5B
and for the closing ] use %5D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With