Cannot access project text files in VS2005

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Consider a WindowsApplication in VS2005 named "MyApp". In addition to the
default "Resource" folder you create a new project folder named "NewFolder"
and add a text file in this folder named "TextFile1.txt" and a C# class named
"Class1.cs".
The project hierarchy would then look like this in the Solution Explorer:

======================
Solution 'MyApp'
-MyApp
...
+Resources
NewFolder
Class1.cs
TextFile1.txt
===============

The "Class1.cs" file (included in the project namespace) can be accessed by
typing 'MyApp.NewFolder.Class1', but how can the text file be accessed
without explicitly writing the entire file path?

For instanse, say you want to read the text in "TextFile1.txt" using the
File.ReadAllText() method. How can the file path passed to the ReadAllText()
method be expressed as a pointer to the text file included in the project ?
(writing File.ReadAllText("C:\\....") is not an option since this of course
will stop working once the project is moved).
 
Sounds like you need a my documents open dialog box and let the user find the
textfile1.text

Good Luck
DWS
 
Back
Top