How to Access Resource File in C# NET [duplicate] - c#

This question already has answers here:
How to read embedded resource text file
(23 answers)
Closed 8 years ago.
I googled my query a lot and got so many references, but it created more confusion for me, So I am putting my question here. I do have my Resource file under Resource folder with path Resources\RR.resx, where Key and Value are stored. I want to know a way through which I can access those Key-Value pairs in back-end code.
(Note: Please make sure it's resource file not resource dictionary)

Considering your example, you can access the Key-Value pair in your code-behind file like,
"Resource.RR.[KeyName]". Here " 'Resource' would be your folder name/Namespace, 'RR' would be your calss name and [KeyName] would be your key.
However, you should also consider that ass soon as we add any resource file default Access Modifier would be 'Internal', you may have to change to public or use it accordingly.

Properties.Resources.ResourceKey;
Please read localization http://msdn.microsoft.com/en-us/library/vstudio/aa992030(v=vs.100).aspx for more information

Related

How to turn have a .json file as a string in C# [duplicate]

This question already has answers here:
How to read an entire file to a string using C#?
(17 answers)
Closed 5 years ago.
So I have this .json file: temp_file.json
Now all I need to do is get whatever is in this .json file, and put it in a string using C# in Visual Studio 2017.
That's it.
I don't want it to be turned into a object of a certain class or whatever. Just get whatsever in the file, right into a string.
A lot of other questions/answers I have stumbled upon are about desirializing and serializing etc. I don't need that. Just turn the .json file in to a string. No need to write it to a console or whatsoever.
Somewhy I just cant lay my finger on it. It sounds simple to do...
You dont get any simpler than
var contents = File.ReadAllText(#"drive:\path\to\yourfile.json");

Variable in c# resource [duplicate]

This question already has answers here:
Why are persisted user settings not loaded?
(2 answers)
Closed 7 years ago.
I am working on a project and I need a kind of variable that save the value and after restarting the program, the value won't get refresh.
For example:
Home Page of a web browser that when you change it, it will save and after restarting the application, it won't reset to the first Home Page Address.
I thought that I can do it using application properties settings
Properties.Settings.Default.
But it didn't work.
If the setting is application wide, and not per user, you can use the AppConfig to store the value. A similiar question was asked here.
Sample code copied from Amol M Kulkarni:
Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
config.AppSettings.Settings.Add("YourKey", "YourValue");
config.Save(ConfigurationSaveMode.Minimal);

How to Hold a Collection in a RESX file?

Is it possible to have a single key in a resx file reference a List, or some other collection?
I noticed this question asked elsewhere, but those who answered didn't seem to understand the question.
In other cases, I see discussion of how to iterate through keys in a resx file.
I suspect it isn't possible to have a single key which has a collection as a value. I suspect that iterating the resx file is indeed the only substitute - but I want to know what others have found.

Adding resources and setting Exe description [duplicate]

This question already has an answer here:
How can we add embedded resources to a file which is compiled from a source file at run-time
(1 answer)
Closed 9 years ago.
I am generating C# code at runtime and compiling it with the CSharpCodeProvider The two problems I'm having are
How to add resources to the generated exe?
How to set the executable description (i.e company name and others) to it?
Thanks.
Have a look here my friend. I think this will sort you out as the guy was having the very same issue:
How can we add embedded resources to a file which is compiled from a source file at run-time

Adding a separate file for all website content [duplicate]

This question already has an answer here:
Getting text from the Resource file in asp.net 4
(1 answer)
Closed 8 years ago.
Thank you in advance for your help.
I have a website in asp.net and c#, i need to have it that all text that is in the site should be taken from a separate file, so it can be changed easily if needed, and for other similar reason.
Hope this id clear.
What is the best way of doing such a thing?
You'll want to read up on resource files, globalisation & localisation. There is a binding expression, similar to <%# that can read the values from the resource files.
This should get you started: http://msdn.microsoft.com/en-gb/library/fw69ke6f.aspx
Simon
I would be tempted to keep your solution 'un-compiled' and then use resource files.

Categories