Hello,
I want a button on my form that the user can click on that will allow them to upload a picture (s) which will then appear on the form.
This is my code:
Protected Function UploadFile(ByVal fileUploadCtrl As FileUpload, ByVal relativePath As String) As String
Dim filePath As String = String.Empty
Dim returnValue As String = String.Empty
Dim actualfilename As String
Dim fileName As Guid
fileName = Guid.NewGuid
Dim strsave As String
Dim FileExt As String
'Check file is uploaded'
If FileUpload1.HasFile Then
'Check file name is not empty'
If fileUploadCtrl.FileName.Trim() <> String.Empty Then
'Check it has extension'
If fileUploadCtrl.FileName.Trim().LastIndexOf(".") <> -1 Then
'Getting file name without extension'
actualfilename = fileUploadCtrl.FileName.Trim()
Dim ext As String = actualfilename.Substring(actualfilename.LastIndexOf("."))
'Moving file to particular directory'
ext = ext.ToLower
If ext = ".jpg" Or ext = ".gif" Then
fileUploadCtrl.SaveAs(relativePath & fileName)
strsave = (relativePath & fileName.ToString & ext)
fileUploadCtrl.SaveAs(strsave)
lblmsg.Visible =
True
lblmsg.Text =
"Successfully uploaded!"
returnValue =
"" & fileName.ToString & ext
Session(
"photopath") = "" & returnValue
Else
lblmsg.Text =
"ONLY IMAGES PLEASE"
End If
End If
Return returnValue
End If
End If
End Function
Protected Sub btnupload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupload.Click
Dim clickonuploadbutton As Integer
clickonuploadbutton = 1
Dim result As String = UploadFile(FileUpload1, Server.MapPath("/test/propertyimages/"))
If (FileUpload1.FileName = "") Then
lblmsg.Visible =
True
lblmsg.Text =
"Please select Image to upload"
End If
End Sub
End
Class
The problem i have is that i am getting several error messages which are as follows:
- fileupload1 is not declared
- iblmsg is not declared
- session is not declared
-server is not declared
- and operator "&" is not defined for types string and system.guid
thanks for your help