Re: How to Access Resource File from a Class Library ?
You mean you want to allow consumers of your library to access a resource in the library? Or you want to pass in a resource from say a .exe that your library can use?
Re: How to Access Resource File from a Class Library ?
Yes, I want consumer to access Resource file in Library.
Example:
I have my Project Class Library called LibPublic under C:\Projects\LibPublic.
And I should the following files:
C:\Projects\LibPublic\CConnection.cs
C:\Projects\LibPublic\CConnection.resx (or. resources)
C:\Projects\LibPublic\CUser.cs
C:\Projects\LibPublic\CUser.resx (or. resources)
...
So, for each class I want to have a resource file and access it when i need to return a specific message
Last edited by paulnamroud; Jun 8th, 2011 at 08:36 AM.
Re: How to Access Resource File from a Class Library ?
I have some help for this issue ... So now, I can do the following where I have only one Resource file Resources.resx: LibPublic.Properties.Resources.ResourceManager.GetString("RecordType_Missing").ToString() where LibPublic is the name of my Class Library.
I have already worked on a Website Project where we can create our classes under App_Code Folder(e.g. App_Code/CCustomer.cs), and then we can create all related Resouces File under App_GlobalResources(e.g. App_GlobalResources/CCustmomers.resx or App_GlobalResources/CCustmomers.fr.resx ... ) . And we can acces the resouces files by doing the following: Resources.CCustomers.FirstName_Missing.ToString()
So I would like to know if there's a way to have a resource file for each class inside my Class Library or something similar to what we have in a Website Project ?
Re: How to Access Resource File from a Class Library ?
It's easy to create one, just create a new resource with the same name as the class. You will get a warning every time you try to edit it however, as it believe you should be using the forms/project designer tool. I have just done it here to test, but have no idea what it can break. There is a warning for a reason . As long as you don't try to convert it to a form later on ...
Re: How to Access Resource File from a Class Library ?
If you were using VS2008 or higher you can change the modifier for the resources from Friend to Public which makes the resources accessible to a project which uses the class library.
In VS2005 you can do it as follows but understand that if you add new data to your resources after the fact the following will have to be done over again.
Under Project menu select Show all files
Open Resources.Designer.vb
Change Friend to Public
Code:
Friend Module Resources
Code:
Public Module Resources
For each string item change from Friend to Public
Do the same if you have added a resource file to the project.
So in the attached VS2005 project there is a library with a stub Class1 class and for resources
My.Resources.UserAccount
In Class1Resources.resx
My.Resources.Class1Resources.FirstNameMissing
The Windows form project uses the class library and accesses the resources
Code:
Public Class Form1
Private Sub Form1_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = ClassLibrary1.My.Resources.UserAccount
TextBox1.Text = ClassLibrary1 _
.My.Resources.Class1Resources.FirstNameMissing
End Sub
This may not be acceptable but is an alternative
Last edited by kareninstructor; Jul 20th, 2011 at 01:00 PM.
Re: How to Access Resource File from a Class Library ?
Thank you Kevin for your answer!
It works fine since I'm using VS 2005 so i have to do the chnages manually evry time i need to add/modify a resources.
Re: How to Access Resource File from a Class Library ?
Originally Posted by paulnamroud
Thank you Kevin for your answer!
It works fine since I'm using VS 2005 so i have to do the chnages manually evry time i need to add/modify a resources.
Yes, in VS2005 you must do the changes manually. Of course if you add all resources at one time you do the manual change one time but life is never that way is it.