Came across a situation that requires accessing string value stored in resource file based on the key provided from code behind.
how can i do this?
Note: the resource file exist in a web project in my solution which i want to access from my silverlight application..
Call the GetLocalResourceObject or GetGlobalResourceObject method to read specific resources from a global or local resource file, respectively. These overloaded methods are available in the HttpContext and TemplateControl classes.
Open your project in Visual Studio and navigate to Solution Explorer. Expand the Resource Files folder, then: To open in the text editor, double-click the . manifest file.
resx resource file format consists of XML entries that specify objects and strings inside XML tags. One advantage of a . resx file is that when opened with a text editor (such as Notepad) it can be written to, parsed, and manipulated.
Assume that your resource file name is "Resource.resx", and you want to pass key dynamically then,
using System.Resources;
string resVal = Resource.ResourceManager.GetString(dynamicKeyVal);
Let me know if it not works, I will work on it and will provide the appropriate solution.
You can use ResourceManager class:
ResourceManager myManager = new ResourceManager(typeof(MyResource));
string myString = myManager.GetString("StringKey");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With