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???
-
http://stackoverflow.com/questions/676312/modifying-resx-file-in-c-sharp – kol Dec 04 '11 at 01:15
-
that doesn't help me much there must be an easier way then that – user1063793 Dec 04 '11 at 01:17
2 Answers
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.

- 417
- 2
- 11
-
I was thinking of maybe having panels or something along those lines in the html file which I could refer to in the c# code which would then display the information within those panels in the html file if that's possible???? – user1063793 Dec 04 '11 at 01:28
-
I dont know what you mean with panels, but if you want to fill the template with values you can use string.Format(): Template: {1} Code: string.Format(templateString, uri, "Click me"); string.Format fills the template string with a variable number of arguments, which can be referred to with "{
}". http://msdn.microsoft.com/en-us/library/b1csw23d.aspx – Dominik Weber Dec 04 '11 at 01:38 -
so say i have paragraph tags in the html file can i replace the text in the paragraphs in the file? say using string.replace("old text","new text") something along those lines by referring to the
tags?
– user1063793 Dec 04 '11 at 01:45 -
You can not change the content of the resx file. You can however define the resx file like this: "
{0}
" and then replace {0} at runtime with the actual text. Remember you can not save the result of this replacement back to the resx file, as this file does not exist in the deployed project. The resx file is only available on the developer machine and is compiled directly into your exe-file. If you want to change whats defined in the resx file at runtime you should use another mechanism, like writing the value into a configuration xml file oder the windows registry. – Dominik Weber Dec 04 '11 at 01:55
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.

- 44,465
- 11
- 90
- 113