Click here to Skip to main content
14,367,061 members

“Ioexception was unhandled” that error keeps appearing, how do I get rid of this error

Ervin Matlapeng asked:

Open original thread
I busy trying file Streaming but i keep on getting the above mentioned error more especially accompanied by:

"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."

but the file is not opened or used by any other program

What I have tried:

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()

        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
Tags: VB.NET

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100