Click here to Skip to main content
15,913,124 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I have some .txt files in the resources of my vb.net project. I am trying to use the command:

VB
FileOpen(1, "FILE NAME", OpenMode.Input)


How do I use my resource location as the file name?

Thanks
Posted

You place your .Txt file in Debug folder of your Project insted of Resourses.Then you can get this path dynamically using following code :
VB
Dim Path As String = My.Application.Info.DirectoryPath
'It returns the Path of the Debug folder where your Exe file created.

Code to get Resource folder path :
VB
Dim Path As String = My.Application.Info.DirectoryPath
Path = Path.Substring(0, Path.LastIndexOf("\"))
Path = Paht.Substring(0, Path.LastIndexOf("\")) & "\Resources"
MessageBox.Show(Path)


I hope it will help you.
 
Share this answer
 
v2
Comments
RoomTen 26-Nov-11 9:33am    
I would like it to still be able to work self standing of the debug folder for when I build it into a .exe . Do I need to use something else?
Sergey Alexandrovich Kryukov 26-Nov-11 22:38pm    
Forget it. You don't need anything like that if you use resource. Please see my solution.
--SA
Manoj K Bhoir 26-Nov-11 9:40am    
Check out the updated solution!
Manoj K Bhoir 26-Nov-11 9:42am    
I think Path is not required because all resources are added into the .exe while building the project.
If you put your text file in the .resx resource, you don't need anything to read it. As soon as you create a resource, an auto-generated source file is created. Look at this file: it has a static class (module) and a static ("Shared") property in it; the name of this property will be the same or close to the name of your original file. Use this property directly in your code: its value will be equal to the content of the source text file.

You can use this rule for many other cases. Suppose you have a PNG file and added it to some resource file. The property in the auto-generated file will be of the type Bitmap; and you can use it directly. You won't need to read resource stream or anything like that.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900