Access .txt file in solution folder

jimmajsterski

Well-known member
Joined
Oct 29, 2004
Messages
53
Location
Houston, TX, USA
Programming Experience
10+
Environment:
Visual Studio 2010 Express, .NET 4.0,
Visual Basic.net

Question:
I have a file "filename.txt" in my solution folder.
Can my running project read/write filename.txt ?
Can filename.txt be accessed by notepad or other editors
totally independent of Visual Studio ?

Hopefully, all I need is nudge in the right direction. . .
Regards, Jim
 
Select the file in Solution Explorer and configure its properties "Build Action" and "Copy To Output Directory". To use as file in output select 'Content' and Copy mode.
 
Assuming that you have done as JohnH says, you can then access the file in code from the same folder as your EXE was run from. That would look something like this:
Dim filePath = IO.Path.Combine(Application.StartupPath, "filename.txt")
Dim fileContents = IO.File.ReadAllText(filePath)
It's just a file like any other so yes, other applications can read and write that file, just like any other file.
 
Back
Top