Im having this problem and it doesnt seem to go away. Theres a code ive done in vb.net, in which i to to stream files but i keep on getting that error
"IOException was unhandled" The process cannot access the file 'C:\Users\Lenovo\documents\visual studio 2010\Projects\File streaming\File Streaming\bin\Debug\banking.xls' because it is being used by another process.
Heres the code:
Imports System.IO
Imports System.Windows.Forms.Form
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
Dim FileStr As New FileStream("banking.xls", FileMode.Create, FileAccess.Write)
Dim a As New StreamWriter(FileStr)
'a.WriteLine("File should be displayed in the RTB............")
'a.Close()
**ERROR APPEARS HERE**
FileStr = New FileStream("banking.xls", FileMode.Open, FileAccess.Read)
Dim i As New StreamReader(FileStr)
i.BaseStream.Seek(0, SeekOrigin.Begin)
If i.Peek() > -1 Then
rtbDisplay.Text &= i.ReadLine()
End If
i.Close()
End Sub
Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click
rtbDisplay.Text = ""
End Sub
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Function FileStream() As Object
Throw New NotImplementedException
End Function
End Class