Protected Sub UpLoadThisFile(ByVal upload As FileUpload)
If UpL1.HasFile Then
Dim fileName As String = Path.GetFileName(UpL1.PostedFile.FileName)
UpL1.PostedFile.SaveAs(Server.MapPath("~/AltImg2/") + fileName)
UpImag.ImageUrl = ("~/AltImg2/") + fileName
T8.Text = ("~/AltImg2/") + fileName
Else
T8.Text = "~/NOPic/noimage.jpg"
End If
End Sub
Protected Sub CheckImag()
If UpL1.HasFile Then
Dim ValidatFileTy As String() = {"bmb", "gif", "png", "jpg", "jpeg"}
Dim Ext As String = System.IO.Path.GetExtension(UpL1.PostedFile.FileName)
Dim isValidFile As Boolean = False
For i As Integer = 0 To ValidatFileTy.Length - 1
If Ext = "." & ValidatFileTy(i) Then
isValidFile = True
End If
Next
If Not isValidFile Then
MsgLbl.Visible = True
MsgLbl.ForeColor = Drawing.Color.Red
MsgLbl.Text = String.Join(",", ValidatFileTy)
Exit Sub
Else
UpLoadThisFile(UpL1)
End If
Else
UpLoadThisFile(UpL1)
End If
End Sub
and in button
Protected Sub BTAddNew_Click(sender As Object, e As EventArgs) Handles BTAddNew.Click
Try
CheckImag()
Insert()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
but how about for online database that is hosted in the internet and does not have a working directory?
yes you must use ~ ("~/AltImg2/").