Click here to Skip to main content
15,884,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Private Sub btnbrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbrowse.Click
       Dim img As String

       Dim myStream As Stream = Nothing


       ' openFileDialog1.InitialDirectory = Application.StartupPath
       OpenFileDialog1.Filter = "Image Files(*.jpg)|*.jpg|Image Files(*.png)|*.png|Image Files(*.bmp)|*.bmp|Image Files(*.gif)|*.gif"



       If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
           Try
               myStream = OpenFileDialog1.OpenFile()
               If (myStream IsNot Nothing) Then
                   txtfile.Text = ""
                   img = OpenFileDialog1.FileName
                   txtfile.Text = OpenFileDialog1.FileName
               End If
           Catch Ex As Exception
               MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
           Finally
               If (myStream IsNot Nothing) Then
                   myStream.Close()
               End If
           End Try
       End If
   End Sub



I am using the above code when i click the browse button in windows7 the following error occurs .
"
Attempted to read or write protected memory.This is often an Indication that other memory is corrupt"

Please help me guys I have stucked ...
Posted
Comments
Valery Possoz 1-Sep-15 17:58pm    
There does not seem to be anything in this code that can trigger this exception. Have you try to debug it? add a breakpoint and go step by step until you find the line that causes an issue.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900