我的网页上有一个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
答案 0 :(得分:0)
尝试
img1.ImageUrl = "/MWP/Images/" & FileUpload1.FileName
另外,除非你需要其他地方的文件路径,否则你不需要使用Session,只需使用
string filePath = Server.MapPath("/MWP/Images/") & FileUpload1.FileName
FileUpload1.SaveAs(filePath)