Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one xml file and text added in the resource folder of my vb.net project and i want to use it in my code how can i access those files??

What I have tried:

I tried to use
My.resources.<filename>
but its not working
Posted
Updated 13-Mar-17 4:12am
Comments
CHill60 13-Mar-17 9:44am    
Have you just added the files to the resource folder OR have you actually added them as resources?

1 solution

Assuming you have added the files as resources, select the file(s) in the Solution Explorer and make sure the "Build Action" property is set to "Embedded Resource"

You can then get to the text like this:
VB
Dim filetext As String
Dim ass As Assembly = GetType(yourClassName).Assembly
Using reader As New StreamReader(ass.GetManifestResourceStream("yourNamespace.yourTextFile.txt"))
    fileText = reader.ReadToEnd()
End Using
You can also load the text of the file with
VB
fileText = My.Resources.Resource1.yourFileName

If you are loading XML in this way then remember to use the LoadXml method and not Load because the file will have been returned as a (large) string NOT a file name
 
Share this answer
 
Comments
Member 13007431 14-Mar-17 0:25am    
okay thank you

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