tags:

views:

574

answers:

4

I added a text file to a testapp's solution and I want to read said file. I don't remember how to do this, I know it has to do with reflections but I need a push in the right direction.

A: 

I was going to write some code, but instead found a better explanation here

In your case, you'll need to use your application path instead of "C:\".

Saif Khan
+2  A: 

If you add the text file to a .ResX file, you can have all the benefits (dynamic updating, for instance) AND not need to worry about interacting with an actual file. VB will automatically create a class to access the file - suppose you have Resources.resx. You can access it with My.Resources.MyFile - it will return a string.

Rob
even better, thanks a lot :D
Anders
+1  A: 

Did you add the file as a resource? In that case you can access its (String) content by just using My.Resources.name_of_file. Otherwise, the easiest way to read a text file in VB is to use the following.

Dim content = My.Computer.FileSystem.ReadAllText("filename")
Konrad Rudolph
A: 

Are you talking about embedding the text file as a resource in the solution - ie compiled in?

For that you need an instance of an assembly class (referecning yours, Assembly has a static member called GetExecutingAssembly) From there you call the GetManifestResourceStream

keithwarren7