- Creating Resource Files:
- Creating Resx Files in VS.NET (embedding resources):
- Right-click on the project to which you want to add a Resx file and click on Add\Add New Item.
- Choose Assembly Resource File.
- Click on Open.
- Select the data in the left pane and then click on the name column in the right pane.
- Enter a name.
- Enter a value.
To access the resources via the same assembly: 1) Create an instance of ResourceManager 2) pass the constructor the following parmaters: a) "Namespace.ResourceFileNameNoExtension" and b) this.GetType().Assembly. 3) retrieve the resource itself via the ResourceManager.GetString() or ResourceManager.GetObject() method:// Namespace = Test1 // Resource file = TestResource.resx ResourceManager rm = new ResourceManager("Test1.TestResource", this.GetType().Assembly); this.txtTest.Text = rm.GetString("test"); - Creating Resource Assemblies:
Creating a Resx resource assembly is pretty much the same as that outlined in Creating Resx Files in VS.NET (embedding resources) above with the exception being the embedded resource is not part of the current project (the project accessing the resource(s)).
- To create an assembly resource that uses a Resx file, use the steps outlined in Creating Resx Files in VS.NET (embedding resources).
To access the resources of the resource assembly: 1) Create an instance of ResourceManager 2) pass the constructor the following parmaters: a) "ResourceAssemblyNamespace.ResourceFileNameNoExtension" and b) this.GetType().Assembly. 3) retrieve the resource itself via the ResourceManager.GetString() or ResourceManager.GetObject() method:// Namespace = ResourceAssembly // Resource file = TestResource.resx ResourceManager rm = new ResourceManager("ResourceAssembly.TestResource", Assembly.LoadFile(Application.StartupPath + "\\ResourceAssembly.dll")); this.txtTest.Text = rm.GetString("test"); - To create an assembly resource that uses a resources (binary) file: Use the steps outlined above, only instead of adding a Resx file, create a .resources file using the ResEditor utility. You should be able to find this utility in "%PROGRAMFILES%\Microsoft Visual Studio .NET 2003\SDK\v1.1\Samples\Tutorials\resourcesandlocalization\reseditor".
To access the resources of the resource assembly: perform the same steps as above.
- To create an assembly resource that uses a Resx file, use the steps outlined in Creating Resx Files in VS.NET (embedding resources).
- Creating Resx Files in VS.NET (embedding resources):
Mike's a long-time, C# developer, with experience in database development, software architecture & design, .Net, ASP.NET, HTML, JavaScript, VB, CSS, Flash, SQL Server, Oracle, and more.
Sunday, September 18, 2005
Assemblies Notes
Subscribe to:
Posts (Atom)