Text into a html file thats placed in a resx file - c#

My question is this I have a console app that sends out emails and i have a html email template setup thats placed into a resx file, now i want to be able to update the html or add text to the html file at runtime how can i do this???

As the resx file is compiled into a dll or exe it is not easily possible to change its contents. You could offer a configuration gui or use some xml configuration files like the app.xml.
If you want to offer updates to the template file like localization you could create multiple resx files File.resx for default language, File.en.resx for english, File.de.resx,...
Visual Studio then creates multiple dll files en\Resources.dll, de\Resources.dll. Whenever a user starts your application it will autmatically search the installation path for these files und use the one best suited for the language selected in the user's operating system.

I think you would have a much easier time if you moved the template from a direct resource string into a project-level file that is stored as Content or an Embedded Resource.

Related

Visual Studio plugin to show the text from a resource file instead of the code

We've been implementing resource files for our globalisation.
Quite often I'll need to search for some text where a user is reporting a mistake or for whatever reason. Obviously now we use resource files all the text is replaced with code to go grab the required string from the resource file
Are there any features in VS or plugins that allow you to open up a cshtml page and have it show the default resource file entries rather than the code?
Thanks
Check out the String Resource Visualizer https://marketplace.visualstudio.com/items?itemName=MattLaceyLtd.StringResourceVisualizer
This extensions works fine for cs files and I hope it will work for cshtml.

Use external existing file as resource file in .NET

I'm writing some integration tests for some SQL scripts that live in a folder separate from the project. Since the setup of the machine I'm writing on the tests on differs from the machine they will be run on, I would like to include them as resource files rather than hard coding any paths. However the default behavior for adding an existing file as a resource file simply copies the file, which is not what I want in case any of the SQL scripts get updated.
Does anyone know the best way to get the resource file to actually reference the SQL scripts that are in a folder separate from the project, or to somehow copy them into the assembly at compile time so I don't have to load them via absolute/relative paths?
Edit: For clarity, I'm trying to get the resource file to act as a symlink to the original file at compile time. Adding an existing file to a resource in file in Visual Studio simply makes a copy of the file, which means any changes to the original are not propagated to the resource file.
After asking on IRC, someone guided me to what I was looking for. You are able to add an existing file to a project as a link (there is an arrow on the Add box when in the file dialog), and set it's Build Action property to Embedded Resource
https://support.microsoft.com/en-us/kb/306234
Daniel posted a link on how to actually read an embedded resource:
How to read embedded resource text file

Changing String Resources in C#.net

I added some strings to string resource file in my C#.net project (using MS Visual C# express 2010). Properties of Resource file are set as follows
Copy to output Directory: Copy Always ,
Build Action: Embedded Resource
When I compile the application under the bin/release it creates the folder Resources and copies the StringLiterals.Designer.cs and StringLiterals.resx.
My Requirement:
I need to edit the string resources from another application pro-grammatically. Using ResXResourceWriter I was able to change the resource file StringLiterals.resx. Could you please let me know if there is a way to use the changed string resources in my main Exe without Recompiling.
I don't believe that you can change an embedded resource file without recompiling. You should consider using a configurable XML file or writing to the registry. This is usually how application settings are stored. If you're worried about text being stored in a readable format, you might consider encrypting the text before writing to the file and decrypting when you need the text.

.net localization for non-strings

I am localizing a WPF application using .resx files. I created copies of main Resources files like Resources.en-US.resx or Resources.cs-CZ.resx. Works well for strings. However, I can't figure out how to localize other files like images or documents in resource files.
When I add a new image to Resources file (either Resources.en-US.resx or Resources.cs-CZ.resx), a copy of the file is always copied to /Resources directory. So there cannot be multiple versions of one file for multiple languages, because in one directory there can be only one file with same name.
Ideal solution would be if images from localized resources would be copied in subdirectories like /Resources/en-Us. In current conditions, I am unable to localize images and documents using .resx files. Any ideas how I can achieve this? Thank you.
The following MSDN post Resources and Localization in ASP.NET 2.0 - Displaying Localized Images states:
While ASP.NET 2.0 doesn't directly support localizing image files, it doesn't require too much custom code to achieve the desired effect.
And provides the following work around:
You can start by adding the localized versions of an image file to localized versions of a global resource file. For example, the English version of LitwareSlogan.png has been added to the global resource file named Litware.resx while the French version of LitwareSlogan.fr.png has been added to Litware.fr.resx. The resources in both resource files have been given the same name of LitwareSlogan.
Complete sample code is provided at the site.

hiding xml file in windows form application

I have a language file and a settings file of my windows application. This files are in xml format and they are shown in the release folder. I want to hide, crpyt or something like that to that files so users can not see either reach my files.
What is the best way to do this.
how does it fit your needs to simply have another extension instead of .xml so the user does not know how to open the files?
you can also set the files as "Embedded Resource" and load from resource so it will be inside the dll itself instead of being available outside as separate file.
other option is to encrypt the file which could be good as well, up to you.
for a very small file, I would embed it.

Categories

Resources