hiding xml file in windows form application - c#

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.

Related

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.

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/embedding files inside .exe

I have a .OCX file that I use in the system to fix a problem with an application that I use at work. But now, I`m building an application to be able to fix it and publish this file among my colleagues ... I want to make a single .exe file that will extract the .OCX file to a certain place in the system, overwrite if exists, and then use it as I want to. I want to know how to hide/embed the file in my application and how to extract it to certain location in the system. I want to know also how to call system commands from within my application like regsvr32, ect ...
Add the file you would like to extract to your solution. Then right click, press properties and choose "build action" "embedded resource".
This link shows how to access the resource stream from within the exe: here
To run an application simply use:
Process.Run("regsvr32....");

Windows Shell: How to associate different xml-files with different apps?

I have many kinds of xml-files (all with extension .xml) with different root element name and namespace. I want to associate each type with a different application and also make it possible to have different file-icons for each type. Can this be done using C# .NET?
The only way to handle this is in a similar way to that which Visual Studio uses to handle .sln files which is the Visual Studio Version Selector. This application is the one that gets associated with .sln files and handles providing an icon and an eventual process to handle the specific .sln file. Assuming you have Visual Studio installed, take a look in the registry at HKEY_CLASSES_ROOT\VisualStudio.Launcher.sln to see how it's done.
So basically you need to:
Write an executable that can decide what to do with .xml files
Register the process as the one responsible for handling .xml files
Place logic in your executable, or in configuration that your executable consumes, that decides what to do on a per file basis.
For icons, take a look at the subkey ShellEx\IconHandler. You'll see that it points to (on an x64 machine with Visual Studio 2010 installed) HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{9A2B23E4-2A50-48DB-B3C3-F5EA12947CB8} which lists under InprocServer32 a DLL that is responsible for providing icons for files, in this instance C:\Program Files (x86)\Common Files\Microsoft Shared\MSEnv\VSFileHandler.dll. You'll need to implement a similar DLL that shares the configuration/logic of your launcher process to determine what icon to show on a per file basis.
The usual caveat: Writing shell extensions in managed code has always been a big "no no" because shell extensions get loaded into any process that shows the common file dialogs. This can cause merry chaos as, up until .net 4.0, only one version of the CLR can be loaded into a process, so you have to be very sure before doing this. Given that .net 4.0 supports in-process side by side, this may not be an issue for you.
No. To Windows, an XML file is an XML file. The OS doesn't look inside to see what namespace is associated with it; it's just an XML file.
Windows associates file types with their extension, so again, all XML files are XML files. You can see this for yourself: rename a normal .txt file that contains absolutely no XML, and then refresh the view of it's folder in Explorer. You'll see the icon change from a text file image to an XML file image.
There isn't a way that you can do this without having custom extensions or an intermediary program.
Maybe one option would be to have a custom applicaiton which is assigned to handle XML files. When this is program is spawned it works out what the "type" of the file is using one of the XML tags and spawns the correct process accordingly. It's unlikely, however that you can give different "types" different icons.

Categories

Resources