Saving a file in resource folder of project - c#

Like following,
The Media.html file is located in the folder of project.
How can I save this file outer user's local disk?
EDITED
**Sorry for question insufficiently. I mean how copy a resource file like Media.html to disk programatically, in runtime, not VS2010 environment.

You may use C#'s file handling techniques, use File.Copy method. Please go here

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

How to programatically acces user.config file in AppData folder

I'm trying to access the user.config file of another application in C#. I understand that I can use ConfigurationManager.OpenExeConfiguration().
I am talking about the user.config that is stored under AppData\Local\MyApp, not the configuration file I find in the same folder as the application.
Is this even possible?
The full path of the application data is in this form:
C:\Users\markn\AppData\Local\MyCompany\MyApp.exe_Url_pn34t01n4nbvali2df02umn4jhetpy0c\5.25.4969.26783
I just hope there is a call in the .NET framework somewhere that will allow me access to this file, without my having to resort to recursing all the directories looking for the file.
Thanks a lot.
Mark

Adding a whole folder (with subfolders) as embedded resource?

I have an application that upon execution It copies two folders with subfolders that are in the same location to another windows location %AppData%
Now I have the following files :
MyApp.exe , Folder1, Folder2
In each folder there are subfolders. How to embed these two folders as resources inside the application so after compiling the program, I get only one executable file. And when I click on it, it extract the two folders to the same location then do the rest of job.
I know how to add a file as embedded resource then retrieve it using reflection,
but how about a folder Is that even possible??
I had to solve this problem recently. I embedded a ZIP file, and then decompressed it at runtime.
.NET 4.5 includes ZIP functionality. If not, use SharpZipLib or DotNetZip.

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.

Execute file in resourses folder without copying it to disk

I have an executable file in the resources folder. I am able to run that file by writing it to the disk then locating the file and use the Process.Start method to run the executable. Here is an example of how I do this:
How can I execute the file without writing it to the disk. Is there a way I can execute the file from memory? Or maybe execute it directly from the resources folder?
You can't. One of the very hard requirements of Windows, an executable must exist on disk. It is fundamental to its architecture. Slowing down the malware authors is a happy side-effect. Google "memory mapped file" if you want to learn more about it.
If it's a .NET exe try Assembly.Load(byte[]). Be wary of CAS though.

Categories

Resources