【问题标题】:I make fileUpload to save images in folder now i want to display it我制作文件上传以将图像保存在文件夹中,现在我想显示它
【发布时间】:2016-09-22 14:29:16
【问题描述】:

这是从文件夹中获取图片url的代码

 <asp:Repeater ID="rptImages" runat="server">
    <ItemTemplate>
        <li>
            <img alt="" style='height: 75px; width: 75px' src='<%# Eval("Images") %>' />

        </li>
    </ItemTemplate>
</asp:Repeater>

这确实显示图像

string[] filesindirectory = Directory.GetFiles(Server.MapPath("~/Images"));
List<String> images = new List<string>(filesindirectory.Count());

foreach (string item in filesindirectory)
{
    images.Add(String.Format("~/Images/{0}", System.IO.Path.GetFileName(item)));
}

rptImages.DataSource = images;
rptImages.DataBind();

当我运行它时,它说:“在编译服务此请求所需的资源期间发生错误。请查看以下具体错误详细信息并适当修改您的源代码。”

并以红色显示:(List&lt;String&gt; images = new List&lt;string&gt;(filesindirectory.Count());)

我该怎么办?

【问题讨论】:

  • 看看这个post from SO对你有没有帮助?
  • 还是不行
  • Server.MapPath("~") 返回应用程序根目录的物理路径。此路由路径上是否存在您的 Images 文件夹?
  • 当我上传图片时转到文件但它没有出现
  • @sagar 文件夹中的图片和那里的文件夹

标签: c# asp.net database


【解决方案1】:

我没有遇到你提到的错误,但是我在绑定上发现了另一个错误。

在这里您应该使用Container.DataItem 更改绑定,并且由于您使用~ 作为路径,您应该添加runat="server",就像link 中提到的那样。

<img alt="" style='height: 75px; width: 75px' src='<%# Container.DataItem %>' runat="server"/>

【讨论】:

  • 同样的错误。那是错误消息:CS0246:找不到类型或命名空间名称“列表”(您是否缺少 using 指令或程序集引用?)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-09
  • 2021-05-04
  • 2013-11-25
相关资源
最近更新 更多