ASP.NET modify resource values from .resx files at runtime - asp.net

My current requirements for the application that I am working on are that the client should be able to modify the texts used in the interface from a screen within the application itself.
These are of course saved in resx files.
Is there any way to do this?
Modify the values of the resources at runtime?
What would be the easiest way?
Thank you in advance
Edit: resx files are already implemented and there are a lot of keys used all throughout the application

If the requirement is to edit label texts during runtime than I would suggest that you don't use RESX files, as them are ment to be static, but rather use database.

You could write your own provider using a database as backend. This way your code doesn't change and you'll have the possibility to update text directly.

Related

Where is the best and easiest place to store global website settings

I'm just putting together an internal data system for a client, which is ASP.NET VB, backed by an SQL database, on an in-house IIS7.5 dedicated server.
I want to store certain global settings, such as the age limit for news articles, admin contacts etc, in a file NOT within the database (i.e. to avoid unnecessary database query's)
Where would the best place to store this be? global.asax? app.config? or a custom XML file? how would i import these at runtime? (probably to session variables)
ETA:
Also - the settings must be editable from within the site, i.e. an admin section i'm yet to build
If you need these settings to be editable, then the simplest place to store them would be in a database table. You're already building a layer to get in and out with CRUD operations, so adding this little extra won't hamper you. This will also help you keep your web.config clean and your supporting libraries will not need an extra app.config built into them.
Resource files and embedded app.config files are not editable so those preferred methods don't meet your requirements. You don't want people accessing the web.config directly (even through an interface) because changes to the web.config cause the application pool to recycle. A custom XML file would work, but you would have to build a separate parsing engine to get in and out of it. While this is simple, it would be unnecessary since you're already building an access interface for the rest of your database.
If you're really hating yourself though, you could combine the two into a custom xml file stored in the database as an XElement.
Thanks for your suggestions.
I decided the easiest method, given that the details may only need altering a couple of times a year, was to set session variables in global.asax

what are the best practices to separate resource file from the ASP.NET web project?

I have a web application project which contains few resource file. i am planning to create another one project for Mobile where i should be able to use the same resource files.
so can you suggest me some best practices to separate the resource files.
Let me know if you need any clarifications for the same.
It is possible that you can find an answer for your question here. In my opinion it is the best solution in this case
I know this is an old one...but I would create a separate new project, MyProject.Localisation, and then place all the resx files in there. Marking them as Embedded Resource, Do not copy. Then reference that project from what ever project needs the resources.

ASP.NET: Best way to manage global resources?

I've a couple of email templates and I would like to store each in a sepparate file. I'd like to avoid having to read them from disc everytime I need them. Is there any built in structure in ASP.NET that automatically loads them when needed and shares this resources throughout the application?
You can store the email in the Application Dictionary or in the cache or in resource files but in the long run I have found that depending on the size of the file, the amount of files and the frequency of use it is often best to just read it from the disk every time. This way you do not clog memory and you do not have to have any caching code.
If the file is small and you only need it every now and then just read it from the disk. If you only have a few templates and you need them all the time then go with one of the other suggestions. (if the templates are plain text I would use the resource files and not reinvent the wheel, but if you need complex templates you may want something else)
You can use the Cache or Application objects.
Also, for simple tasks, a simple static field would suffice.
You can create a Global_Resources folder in your web app and put global resources files there. (*.resx files)
ASP.NET Caching is good for your problem.
Also you can use Enterprise Library Caching Block.
System.Web.HttpApplicationState

Localization CMS - Admin functionality to edit the localization files for Content Editors?

Are there solutions/tutorials/open source solutions to providing the functionality of having Content Editors edit ASP.net Localization files?
For example,
With Labels.resx and Labels.fr.resx, it would be great if theres an editor out there that allows End Users to end the content of the file.
I would suggest a database solution with caching. I found this article which might help. It has a complete provider along with a very good write up.
Creating a Data Driven ASP.NET Localization
Resource Provider and Editor
http://www.west-wind.com/presentations/wwDbResourceProvider/
ASP.NET 2.0 introduces a provider
model for creating custom Resource
Providers that can store localization
data in stores other than Resx files.
Resx resources are all fine and good
but putting data in a more flexible
resource store gives you many more
options for editing and administering
resources interactively and even at
runtime. In this article I'll
demonstrate how to create a new
Resource Provider that stores resource
information in a database and show a
resource editing tool that makes it
much easier to edit resources
interactively in the context of your
live ASP.NET applications.
Particular bit to note:
Resx Resources are also static – they
are after all compiled into an
assembly. If you want to make changes
to resources you will need to
recompile to see those changes.
ASP.NET 2.0 introduces Global and
Local Resources which can be stored on
the server and can be updated
dynamically – the ASP.NET compiler can
actually compile them at runtime.
However, if you use a precompiled Web
deployment model the resources still
end up being static and cannot be
changed at runtime. So once you’re
done with compilation the resources
are fixed.
I just wrote an application like that because I could not find a free soft that does resx editing:
Reads the content of all the resx files from a folder
Displays the values from different cultures but same resx besides each other
Generates/saves the resx files back
You might consider using structured XML files. Seems like this would be a more elegant solution than hacking .resx files to work in an unconventional way. You could use a LINQ query to get to the XML in a strongly typed manner similar to the resx file. Additionally, XML files could be edited by the user through the presentation layer since they aren't compiled into the application.

ASP.NET XML ObjectDataSource Wrapper Class Examples

I want to use XML instead of SQLServer for a simple website.
Are their any good tutorials, code examples, and/or tools available to make a (prefer VB.NET) wrapper class to handle the basic list, insert, edit, and delete (CRUD) code?
The closest one I found was on a Telerik Trainer video/code for their Scheduler component where they used XML to handle the scheduling data in the demo. They created an ObjectDataSource class. Here is a LINK to that demo if anyone is interested.
[Reply to Esteban]
it would make deployment easier for clients that use godaddy where the database isn't in the app_data folder. also backing up those websites would be as simple as FTP the entire thing.
i have concerns about possible collisions on saving. especially if I add something as simple as a click counter to say a list of mp3 files visitors to the site can access.
In these days of SQL Server Express, I'd say there's really no reason for you not to use a database.
I know this doesn't really answer your question, but I'd hate to see you roll out code that will be a nightmare to maintain and scale.
Maybe you could tell us why you want to use XML files instead of a proper database.
It would make deployment easier for clients that use go-daddy where the database isn't in the app_data folder. also backing up those websites would be as simple as FTP the entire thing.
I have concerns about possible collisions on saving. especially if I add something as simple as a click counter to say a list of mp3 files visitors to the site can access.

Resources