• Sign in to Neowin Faster!

    Create an account on Neowin to contribute and support the site.

  • 0
Sign in to follow this  

The process cannot access the file

Question

keymac    0

Here is my VB.net 2010 code when a cell in a datagrid is clicked strPath being set to the full path of the file 

 

                Dim fs As New FileStream(strPath, FileMode.Create, FileAccess.Write) 
                k = UBound(myData)
                If k > 0 Then
                    fs.Write(myData, 0, k)
                    fs.Flush()
                    fs.Close()
                    fs.Dispose()
                    picImage.Load(strPath)
                    picImage.SizeMode = PictureBoxSizeMode.Zoom
                Else
                    fs.Close()
                    fs.Dispose()
                End If

 

The next time the code is accessed, ie  a cell in the datagrid is clicked I get a "The process cannot access the file" error

 

 

 

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0
+virtorio    3,112

If I remember correctly, PictureBox.Load will lock the file. Your best best is to load an Image object from the file and set the PictureBox.Image property.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.