Changing String Resources in C#.net - c#

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.

Related

How to merge a file to a precompiled exe application

I have designed and created two seperate windows application ( say winapp1 and winapp2). Winapp1 creates a file(say file.txt) in the disk containing some text. And I need to merge this file.txt with precompiled version of winapp2 ie winapp2.exe so that the winapp2 can display it.
Winapp1 creates a file with different contents each execution time. And for each file there will be a copy of winapp2 that needs to be merged.
Is there a way to this? If there is, help me.
And my English is not so good. Thanks for reading this.
The easiest solution, (assuming that releasing the source code for winapp2 to the system that runs winapp1 doesn't present problems) is to have the entire source for the winapp2 project accessible to winapp1. The source should include a blank copy of the file as an embedded resource. Winapp1 can then modify the source file and use MSBuild to build a fresh copy of Winapp2.
To modify the text file, you should be able to just use the normal file manipulation .NET methods and to call MSBuild, you may be able to do it via a .NET class, but you can certainly just call the msbuild executable from the relevant .NET framework folder in %windir%\Microsoft.NET\Framework\ and pass in the full path of the project file.

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

Add resx to cab file

I have an app on Windows Embedded which uses .resx files to translate the app to different languages.
Also I create an installation .cab file but I can't include the resx file to this cab.
How can I achieve this?
Thanks for any tip
A few things:
You'd not told us how you're trying to add the file. Are you using a custom INF file and just calling CABWIZ or are you using a Visual Studio Installer Project?
What have you done to try to include the file?
Most importantly, a RESX file does not contain the run-time resources and you rarely would deploy it. The RESX resources get compiled into a *.resource.dll assembly, that is typically in a subfolder with a name for the locale (e.g. en-us or fr-ca). You need to deploy those files/folders which is challenging because CABWIZ doesn't allow duplicate file names (and all resources have the same file name, just different folders). That scenario is handled by this SO question.

Text into a html file thats placed in a resx file

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.

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