[英]Image path have special characters when it's bind to gridview
I am trying to bind images to grid-view from path stored in database. 我正在尝试将图像从数据库中存储的路径绑定到网格视图。
lets say path stored in database is ../Images/Products/ScentTower.png
可以说存储在数据库中的路径是
../Images/Products/ScentTower.png
when the image bind to grid view the path appears this format 当图像绑定到网格视图时,路径显示为这种格式
`../Images/Products/ScentTower%0d.png`
what is causing that? 是什么原因造成的?
<ItemTemplate>
<asp:Image ID="imageControl" runat="server" ImageUrl='<%# Eval("Picture") %>' />
</ItemTemplate>
如何确保特殊字符不会首先进入您的文件夹/数据库?
%0d
is the carriage return character ( \\n
). %0d
是回车符( \\n
)。 There is a line break in your file name. 您的文件名中有一个换行符。 I don't know any operating system that allows this, so the best thing to do is make sure you have proper input validation and checks in the database that prevents unwanted characters in your file name.
我不知道任何允许该操作的操作系统,因此最好的办法是确保您具有正确的输入验证并检查数据库,以防止文件名中出现不需要的字符。
One way to validate the file name is to check on Path.GetInvalidFileNameChars()
. 验证文件名的一种方法是检查
Path.GetInvalidFileNameChars()
。 If you don't want to do input validation, you can normalize the image URL by removing or replacing all occurrences from any character in that list. 如果您不想进行输入验证,则可以通过删除或替换列表中任何字符中的所有匹配项来规范图像URL。
"%0d" means '\\n'. “%0d”表示“ \\ n”。
Therefore your path stored in database appears like 因此,存储在数据库中的路径看起来像
../Images/Products/ScentTower
.png
instead of 代替
../Images/Products/ScentTower.png
try to remove any whitespace in column path. 尝试删除列路径中的所有空格。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.