vb.net open text file

XK8ER used Ask the Experts™
how can I open a text file and leave it open so that if I try to write to the file I get file already open error..
I would like to test a few function but I need the (already open)
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Dim sw1 as StreamWriter = New StreamWriter(strPathAndFilename)
Dim sw2 as StreamWriter = New StreamWriter(strPathAndFilename)
You will need to import System.IO, if not already imported.
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Use FileShare.None:

    "Declines sharing of the current file. Any request to open the file (by this process or another process) will fail until the file is closed."

Something like:

    Dim fs As New System.IO.FileStream("c:\some\file.txt", IO.FileMode.Open, IO.FileAccess.ReadWrite, IO.FileShare.None)
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

I am just learning vb, but I came across this that might work -

Dim ff As Integer
On Error GoTo errHandler

ff = FreeFile
Open "c:\sample.txt" For Random Access Write As #ff
Close #ff

    MsgBox "File is Open"

Hello madhatter5501

While i have no intention to discourage your attitude to be helpful, may i bring it to your attention that this question is being asked in Microsoft Visual Basic.NET zone and your answer caters to Microsoft Visual Basic 5.0 / 6.0, the older versions prior to .NET.
thanks for clearing that up :)  sorry for the incorrect answer to the question.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial