Any Help with resources

VB.Beginer

New member
Joined
Jan 18, 2011
Messages
1
Programming Experience
Beginner
Hi
I have an application with text Files,I make a satellite assembly by using al.exe.
Next I add the output file which name is "Res1.reources.dll" to solution explorer and set Build Action To embeded resource.
What I need is to reed the text Files in the dll resource File.
Note: This is the first time i deal with resources.:(
 
Satellite assemblies have their use, but not like that.
Note: This is the first time i deal with resources.
In that case I think you should take a simpler approach, resources is included in projects by default and there is interface for them in IDE, there is even code generation for accessing the resources with the My.Resources object.
In project properties there is a Resources tab, here you can add resources of various types, for example you can copy text files from file system (Explorer) and paste into this page and they are automatically included as resources. Lets say you copy a file.txt into here, then you can get the resource in code like this:
VB.NET:
Dim file As String = My.Resources.file
If you need to add multiple resource sets there is support for that too, simply add a new .resx file to project and when you open it it has same interface as the default project resources. .resx files are xml resource files that has editor support by IDE. Moreover you can set the access modifier from default 'no code generation' to for example 'Friend' and there will be an all separate section generated for My.Resources object. For example you add a newset.resx to project and add a 'test' string resource to it you can get it from code like this:
VB.NET:
Dim test As String = My.Resources.newset.test
If you have had .resx files generated from elsewhere you can add those to project also, code generation support the same.
The .resx files will have Build Action set to Embedded Resource by default.

Further, if you have external .resources files those can be add to project as well (though I'd rather convert them to .resx), but there will not be editor support or code generation for these within IDE, because they are already compiled files. Build Action is 'Embedded Resource' here too. To access such a resource set from code you can do the same the code generation does for .resx files, that is use the ResourceManager class. A side note, .resx files are also compiled to embedded .resources in output assembly. If you had a newset.resources file added and it had a 'test' string resource (and your application namespace was WindowsApplication1) the code would be:
VB.NET:
Dim mgr As New Resources.ResourceManager("WindowsApplication1.newset", Me.GetType.Assembly)
Dim test As String = mgr.GetString("test")
Just to take this up also, if you embedded a compiled dll assembly you would have to use GetManifestResourceStream method to read the dll resource, then dynamically load it as assembly into current AppDomain, then use ResourceManager to load the resource from that assembly, awfully complicated and unnecessary.
 
Back
Top