Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Loading a text file resourse using a variable name

$
0
0
I am making an application where a user logs in, and their data is saved in a text file. Once logged in, their data is read from the text file, line by line, into an array. Now, I have all of this working, but it will only work when I specify the path of the text file; which I do not want.

All of the text files are resources, and are named the same as the username they are associated with; so if user 'testfile' logs in, their textfile is 'testfile.txt'

My problem is that I cannot load the textfiles to read. I have tried using my.resources.resourcemanager(username), (username is a variable that contains the name of the textfile) but get an illegal characters in path message. If I make a string variable equal to my.resources.resourcemanager(username) and display it in a textbox, the path it displays leads to the debug folder, not the resources.

Basically, my problem is how do i replace the filepath in the code below with something that can load resources but change the name of the resource being loaded. I know I could use a variable in the filepath string, but this program is meant to be portable, so the filepath will change totally - so I don't really see it as a viable option.

data = IO.File.ReadAllLines("C:\Users\Ben\Documents\myproject\Resources\testfile.txt")
            For Each Myline In data
                temp &= Myline & vbNewLine
            Next


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>