Windows Develop Bookmark and Share   
 index > Windows Forms Designer > UPLOADING A PICTURE
 

UPLOADING A PICTURE

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

pmckeown  Tuesday, October 21, 2008 9:11 AM

Hi pmckeown

From your code, I cannot find the declare statement of “fileupload1� And I can only found “lblmsg�in your code not the “iblmsg� may be you have made a mistake on spelling. Also I cannot found “session�or “server�in your code.

Sincerely,

Kira Qian

Kira Qian  Wednesday, October 22, 2008 9:09 AM

Hi pmckeown

From your code, I cannot find the declare statement of “fileupload1� And I can only found “lblmsg�in your code not the “iblmsg� may be you have made a mistake on spelling. Also I cannot found “session�or “server�in your code.

Sincerely,

Kira Qian

Kira Qian  Wednesday, October 22, 2008 9:09 AM

You can use google to search for other answers

Custom Search

More Threads

• ToolStripControlHost Constructor on type 'System.Windows.Forms.ToolStripControlHost' not found. Issue
• How to invocate a function that is inside of 'main' class?
• designer errors: Object reference not set to an instance of an object
• Bulk Update in .NET
• Suspending Paint Event
• Override PaintValue on UITypeEditor
• ControlArray
• Windows forms designer is disabled
• Serializing a Collection
• error creating the inherited form