Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File is being used by another process..

Status
Not open for further replies.

theCroat

Technical User
Sep 27, 2006
20
HR
Hello! i'm having difficulties with "File is being used by another process.." and this is all the code i've got in my form:
Code:

Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load picture.Image = Image.FromFile(Application.StartupPath + "\boots\0000.BMP") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim filename Dim ehsen As String dlgOpen.ShowDialog() filename = dlgOpen.FileName picture.Image = Image.FromFile(filename) 'u?itavanje slike FileCopy(dlgOpen.FileName, Application.StartupPath + "\boots\0000.BMP") 'kopiranje u?itane slike u odre?eni direktorij End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Form2.Show() End Sub End Class

and one more thing, when i remove [which i cant remove for final exe because i need this] this code:
Code:

picture.Image = Image.FromFile(Application.StartupPath + "\boots\0000.BMP")



it doesent show error, but i repeat, i need to use this function to load file after your run exe !
 
Code:
Public Class Form1 
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    picture.Image = Image.FromFile(Application.StartupPath + "\boots\0000.BMP") 
  End Sub 

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    Dim filename Dim ehsen As String 
    dlgOpen.ShowDialog() 
    filename = dlgOpen.FileName 
    picture.Image = Image.FromFile(filename) 
    'u?itavanje slike 
    FileCopy(dlgOpen.FileName, Application.StartupPath + "\boots\0000.BMP") 
    'kopiranje u?itane slike u odre?eni direktorij 
  End Sub 

  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 
    Form2.Show() 
  End Sub
End Class

Let's put a little format on the code here.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Okay, instead of using Image.FromFile, use .FromStream. Fromfile (and fromStream for that matter) will lock the file until disposed. The difference is that inorder for FromFile to dispose the file, you need to dispose the image. With FromStream you can just dispose the stream.

Code:
dim sr as StreamReader = new StreamReader(filename)
picture.Image = Image.FromStream(sr)
sr.close
sr=nothing

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
i'm sorry but i didnt understand? When i paste

dim sr as StreamReader = new StreamReader(filename)
picture.Image = Image.FromStream(sr)
sr.close
sr=nothing

i get popup message Type StreamReader is not defined!
 
Error
Value of type 'System.IO.StreamReader' cannot be converted to 'System.IO.Stream'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top