FileUpload控件没有填充<asp:image> control?</asp:image>

时间:2013-03-22 03:13:56

标签: asp.net vb.net

我的网页上有一个FileUpload控件,它没有像应该那样填充控件。这样看起来非常直接,但显然我做错了。我在我的IIS中测试这个,所以我的Server.MapPath值是“C:\ inetpub \ wwwroot \ MWP \ Images \ Img1.jpg”。以下是我的代码:

    Protected Sub btnUpload_Click(sender As Object, e As System.EventArgs) Handles btnUpload.Click
    Try
        Dim strFileName As String = ""

        Session("filePath") = Server.MapPath("/MWP/Images/") & FileUpload1.FileName

        FileUpload1.SaveAs(Session("filePath"))
        img1.ImageUrl = Session("filePath")

    Catch ex As Exception
        strMsg = "btnUpload_Click() - " & ex.Message
    End Try
End Sub

1 个答案:

答案 0 :(得分:0)

尝试

img1.ImageUrl = "/MWP/Images/" & FileUpload1.FileName

另外,除非你需要其他地方的文件路径,否则你不需要使用Session,只需使用

string filePath = Server.MapPath("/MWP/Images/") & FileUpload1.FileName

FileUpload1.SaveAs(filePath)