0

I have a FileUpload control on my web page that isn't populating the control like it should. It looked pretty straight forward in doing this but obviously I'm doing something wrong. I'm testing this in my IIS so my Server.MapPath value is "C:\inetpub\wwwroot\MWP\Images\Img1.jpg". Here is my code below:

    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
4

1 回答 1

0

尝试

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

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

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

FileUpload1.SaveAs(filePath)  
于 2013-03-22T03:20:25.880 回答