如何从根目录中的文件夹中显示上传的图像文件?

时间:2014-01-03 10:32:37

标签: asp.net vb.net

用于将数据保存在文件夹中的Aspx.vb代码。

Try
    Dim j As Integer = 0
    Dim hfc As HttpFileCollection = Request.Files
    Dim PathName As String
    For i As Integer = 0 To hfc.Count - 1
        Dim hpf As HttpPostedFile = hfc(i)

        If hpf.ContentLength > 0 Then
            PathName = System.IO.Path.GetFileName(hpf.FileName)
            Dim BookingNumber As String = objWHParent.WHImageTabList.ToList().Item(i).BookingNumber
            Dim FileName As String = BookingNumber + "_WRH_" + (i.ToString()) + PathName
            hpf.SaveAs(Server.MapPath("~/UploadedImages\") & FileName)


            objWHParent.WHImageTabList.ToList().Item(i).FilePath = FileName
            objWHParent.WHImageTabList.ToList().Item(i).Flag = "Warehouse"
        End If
    Next
Catch generatedExceptionName As Exception
    Throw
End Try

上传后我想显示网格中浏览按钮后面上传的每张图片

1 个答案:

答案 0 :(得分:1)

您需要在gridview上添加图像控件,并从您的数据源中提供URL。请参阅以下代码以供参考:

<asp:GridView ID="gvFolder"  runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText = "Image Name" DataField="ImageName" />
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# Eval("ImageURL") %>'Height="150px" Width="150px"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>