Accessing the internal VB.NET file

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

+1


source to share


4 answers


If you add a text file to your .ResX file, you can get all the benefits (like dynamic updates). And no need to worry about interacting with the actual file. VB will automatically create a class to access the file - let's assume you have Resource.resx. You can access it using My.Resources.MyFile - it will return a string.



+2


source


Have you added the file as a resource? In this case, you can access the content ( String

) simply by using My.Resources.name_of_file

. Otherwise, the easiest way to read a text file into VB is to use the following.



Dim content = My.Computer.FileSystem.ReadAllText("filename")

      

+1


source


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

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

-1


source


You are talking about attaching a text file as a resource in a solution i.e. compiled into?

To do this, you need an instance of the assembly class (referencing yours, the assembly has a static member called GetExecutingAssembly). There you call GetManifestResourceStream

-1


source







All Articles