Error IOException was unhandled streamWriter

waheedrafiq

New member
Joined
Nov 19, 2013
Messages
2
Programming Experience
Beginner
Hi guys i am so lost with this particular error

Objective is to write a word from textbox to a text file here is my code:
Dim FILE_NAME As String = "C:\Users\waheedrafiq\Dropbox\University BCU\Visual Basic ICT\Basic_AI\EnglishSpellingABC\englishspelling.txt"


        If System.IO.File.Exists(FILE_NAME) = True Then


            Dim objWriter As New System.IO.StreamWriter(FILE_NAME)


            objWriter.Write(txtUserInput.Text)
            objWriter.Close()
            MsgBox("Text written to file")


        Else


            MsgBox("File Does Not Exist")


        End If
    End Sub


I have look , over it again , and again try so many different example from different sites unable to fix this problem.

all I get when I compile is The process cannot access the file " file path" because it is being used by another process

now I have check task manager and there is no other process using this file , closed all other possible windows so i am only left with the IDE and compiler but still not good

I have attach some screen shots please , please correct my logics o one more thing i have try at the top of the form imported the IO
so above public class frmMain line one Imports System.IO
 

Attachments

  • IOException was unhandled.JPG
    IOException was unhandled.JPG
    31 KB · Views: 28
  • IoSystemError.JPG
    IoSystemError.JPG
    39.3 KB · Views: 23
Hi Guys

I thought I share this finding , please feel to correct me

Dim FILE_NAME As String = "C:\Users\waheedrafiq\Dropbox\University BCU\Visual Basic ICT\Basic_AI\EnglishSpellingABC\englishspelling.tx t" synax error as you can't have space between txt extension this is what it should have been englishspelling.txt


If System.IO.File.Exists(FILE_NAME) = True Then Problem in the rest of the code I never closed system.IO. streamReader objReader.Close() in my case

and that how simple it was , took me over one day and 3 hours to figure that out by myself self :)


Dim objWriter As New System.IO.StreamWriter(FILE_NAME)


objWriter.Write(txtUserInput.Text)
objWriter.Close()
MsgBox("Text written to file")


Else


MsgBox("File Does Not Exist")


End If
End Sub
 
Back
Top