我有数据库存储图像的路径,我想在gridview中显示它。该路径是单击按钮时创建文件夹的位置;文件夹名称与图像名称相同。我已成功创建该文件夹,图像也已成功上传。问题是图像不能在gridview上显示,图像上有空白。在我的数据库中,存储的路径是一个完整的路径,其中的磁盘字母如" C:\ ... \ folder \ image.jpg。"我该怎么办?
button_click:
Dim ext As String = Path.GetExtension(fileupload.PostedFile.FileName)
Dim filename As String = Path.GetFileName(fileupload.PostedFile.FileName)
Dim fileq As String = filename.Replace(filename.ToString, textbox.Text)
Dim folder As String = Server.MapPath(String.Format("~\detail\{0}\", textbox.Text.Trim))
If Not Directory.Exists(folder) Then
Directory.CreateDirectory(folder)
If fcover.HasFile Then
fileupload.SaveAs(folder + fileq + ext)
cmd.Parameters.AddWithValue("@foto", folder + fileq + ext)
End If
End If
的Page_Load:
cmd.CommandText="select image_path from image"
conn.Open()
Dim dt As New DataTable
Dim sda As New SqlDataAdapter(cmd.CommandText, conn)
sda.Fill(dt)
GridView1.DataSource = dt
GridView1.DataBind()
答案 0 :(得分:0)
我已经解决了这个问题,这是代码:
Dim ext As String = Path.GetExtension(fileupload.PostedFile.FileName)
Dim filename As String = Path.GetFileName(fileupload.PostedFile.FileName)
Dim fileq As String = filename.Replace(filename.ToString, textbox.Text)
Dim folder As String = Server.MapPath(String.Format("~\detail\{0}\", textbox.Text.Trim))
If Not Directory.Exists(folder) Then
Directory.CreateDirectory(folder)
End If
If fileupload.HasFile Then
fileupload.SaveAs(Server.MapPath(String.Format("~\detail\{0}\", textbox.Text.Trim) + fileq + ext))
cmd.Parameters.AddWithValue("@foto", String.Format("~\detail\{0}\", textbox.Text.Trim) + fileq + ext)
End If
我只需使用string.format("")
之类的纯字符串而不是我在上面的代码中使用的folder
,图像成功上传,存储路径并显示图像的网格,