4
I have a system developed in Webforms (Eca!) that checks the existence of an image to then display it.
Everything is working correctly, however, when the image path has accents, the method File.Exists
seems to be returning false
.
What can I do to get around it?
Example:
string img1 = Server.MapPath("\Fotos\Imagem.jpg");
string img2 = Server.MapPath("\Fotos\Imagem-com-acentuação.jpg");
Console.WriteLine(File.Exists(img1)); // true
Console.WriteLine(File.Exists(img2)); // false
Update: I wrote and tested the existence of a manually accented file and it worked. I begin to suspect that the problem is in assembling the file path, which was done as follows:
string imgUrl = "~\\Fotos\\Fotos_" + Codigo + "\\" + e.Row.Cells[20].Text;
tries to use Htmlencode:
string img2 = Server.MapPath(Server.HtmlEncode("\\Fotos\\Imagem-com-acentuação.jpg"));
– Rovann Linhalis
@Rovannlinhalis there, let me test here. If the
Text
is sending the encoded values, the problem is probably the same.– Wallace Maxters
@Rovannlinhalis OPA! That’s right, kkkkk. The path was being written like this:
Fotos\Fotos_98\Tiãozão.jpg
. I’ll change it here, I found a bad idea of who made take the right value of HTML :\– Wallace Maxters
Please answer the question :p
– Wallace Maxters
Well, actually, wouldn’t it be the other way around? I think I should use "Decode"?
– Wallace Maxters
I already improve the answer...busy here =] I’m glad you solved =]
– Rovann Linhalis