Why does this error occur? Here is my code:
Imports System.IO
Public Class Form1
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
OpenFileDialog1.Title = "Select Image"
OpenFileDialog1.InitialDirectory = "C:\temp"
OpenFileDialog1.FileName = "Image File"
OpenFileDialog1.Filter = "JPEG Images (*.jpg,*.jpeg)|*.jpg;*.jpeg|Gif Images (*.gif)|*.gif|PNG Images|*.png"
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs)
Dim strm As System.IO.Stream
strm = OpenFileDialog1.OpenFile()
TextBox1.Text = OpenFileDialog1.FileName.ToString()
If Not (strm Is Nothing) Then
' Display the image
PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
Button2.Show()
Button3.Show()
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
OpenFileDialog1.Title = "Select Image"
OpenFileDialog1.InitialDirectory = "C:\temp"
OpenFileDialog1.FileName = "Image File"
OpenFileDialog1.Filter = "JPEG Images (*.jpg,*.jpeg)|*.jpg;*.jpeg|Gif Images (*.gif)|*.gif|PNG Images|*.png"
OpenFileDialog1.ShowDialog()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim clsRequest As System.Net.FtpWebRequest = _
DirectCast(System.Net.WebRequest.Create("ftp://ftp.website.com/uploads"), System.Net.FtpWebRequest)
clsRequest.Credentials = New System.Net.NetworkCredential("ftp_username", "password")
clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
' read in file...
Dim bFile() As Byte = System.IO.File.ReadAllBytes(PictureBox1.ImageLocation.ToString())
' upload file...
Dim clsStream As System.IO.Stream = _
clsRequest.GetRequestStream()
clsStream.Write(bFile, 0, bFile.Length)
clsStream.Close()
clsStream.Dispose()
End Sub
End Class
Can anyone see what is causing this error? It makes the application useless, when I click the button to open the file I want to view in the PictureBox, the dialog to select the file opens but the image file I select does not open. I don't know why this is happening. Here is the debug window:
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\11.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\Jacob\documents\visual studio 2012\Projects\pictureshare\pictureshare\bin\Debug\pictureshare.vshost.exe'
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Deployment\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll'
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualBasic\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualBasic.dll'
The thread 'vshost.NotifyLoad' (0x1650) has exited with code 0 (0x0).
The thread '<No Name>' (0x360) has exited with code 0 (0x0).
The thread '<No Name>' (0x153c) has exited with code 0 (0x0).
The thread 'vshost.LoadReference' (0xe64) has exited with code 0 (0x0).
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\Jacob\documents\visual studio 2012\Projects\pictureshare\pictureshare\bin\Debug\pictureshare.exe', Symbols loaded.
'pictureshare.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Remoting\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Remoting.dll'
A first chance exception of type 'System.IO.FileNotFoundException' occurred in System.Windows.Forms.dll
The thread 'vshost.RunParkingWindow' (0xb60) has exited with code 0 (0x0).
The thread '<No Name>' (0x1010) has exited with code 0 (0x0).
The program '[3844] pictureshare.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[3844] pictureshare.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
Any ideas on how to fix this?