问题:无法使用FilePath显示图像
我有文件上传按钮,它捕获了文件路径&当我点击上传按钮时,它应该显示我选择的图像。但它没有发生?
我错过了什么?我需要将路径转换为图片网址??如果是,那么请提供我背后的代码??
提前致谢..
这是我的代码......
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim path As String
path = Server.MapPath(FileUpload1.FileName)
Image1.ImageUrl = path
Label1.Text = Image1.ImageUrl
End Sub
答案 0 :(得分:0)
您忘了保存文件?
在从服务器显示之前, FileUpload1.SaveAs(string SomeFileNameOnServer)
也应该发生。
(不确定上述行是如何用VB.NET编写的)
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim path As String
path = Server.MapPath("~/.") + FileUpload1.FileName;
FileUpload1.SaveAs(path)
Image1.ImageUrl = path
Label1.Text = Image1.ImageUrl
End Sub