简体   繁体   English

绑定到gridview时,图像路径具有特殊字符

[英]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.

相关问题 在文件路径后附加特殊字符 - appending special characters to file path 从gridview数据中删除特殊字符 - Removing special characters from gridview data 当我们仅在数据库表中存储图像名称时,如何在gridview中显示图像。 如果它位于文件夹内,如何给出imgae路径。 图片 - How to display images in gridview when in database table we have stored image name only. How to give imgae path if it is inside a folder Eg. images 正则表达式只接受9位数字,没有特殊字符,可能只有前导零,最多2位 - Regular Expression accepting only 9 digits, no special characters , may have leading zero's only up to 2 文件路径上的特殊字符:。 斜线符号 - Special characters on file path:. Slash symbol WPF ListView-GridView:绑定图像 - WPF ListView-GridView : bind image 多个字符串在正则表达式中有特殊字符 - Multiple strings have special characters in regex 验证列表已排序且项目具有特殊字符时获取 NUnit AssertionException - Getting NUnit AssertionException when verifying list is sorted and items have special characters 为什么我必须使用Eval访问GridView的数据源的第二级属性,而不是在ASP.NET中绑定? - Why I have to use Eval to access data source's second level properties of a GridView and not Bind in ASP.NET? 将数据绑定到数据表或gridview时出错 - Error when data is bind into data table or gridview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM