C#: Update embeded resource file at runtime - c#

I have a situation, where html files are embedded as resource files in console WebApp and are sent to another app, that hosts them.
I managed to create file change procedure, so that the WebApp is reset and will resend resources, when I edit my html files.
The problem is, embedded files doesn't change.
Is there a way that I can update embedded files at runtime?

No, but you could save the updated files to a folder, and use those files.
When the applications starts, it first checks if the folder with the new files exist. If they do, the application will use them else the application will fall back on the embedded files.

Related

Protecting user files after installation with ClickOne

For example .sqlite files, or use custom files.
How can I protect use files after update? ClickOne every update deletes these files. This is very unreasonable.
You could put any files that need to change separate from the click once files. Probably in the %LocalAppData% folder.
If you have default values you want to keep, you could manage it by creating a copy of the downloaded file in the localAppData, if such a copy do not already exists. If you have a server you could download other files separately if needed.

Include and launch PDF from C# Visual Studio Project

In my C# application i have a help button. When it's pressed I would like for the application to open up a PDF file in the systems default PDF reader, something I can do with a command like Process.Start("pathToPDF").
The problem is that I would like to include the PDF as a resource instead of calling an external file. I do not wish to copy the PDF to the users computer and do not want to host it online or on a NAS.
Right click on your project in the Solution Explorer, then add existing file and choose your pdf (if you cannot find it, make sure you are showing all files and not just .cs files etc.).
Click on the newly added item once in the solution explorer and in the properties window, you set Copy to Output Directory to Copy Always or Copy if newer.
Now you can open the pdf file as expected using Process.Start(filename.pdf);
The only Secure way to show a PDF without providing a file is to include your own Viewer Component (Ex. http://www.o2sol.com/pdfview4net/overview.htm)
Some components allow to load a PDF from Memory (as in a embedded Resource) directly into your Viewer Component, another way would be to create an encrypted binary file to ship with your application and encrypt/load when necessary.
As soon you want to show the PDF in an external viewer ,be aware that the User will have the ability to save the PDF anyway.
Maybe you can explain your reasons to not want to include the file, so we can suggest other solutions to you?
Update:
As noted in your comment, the goal is to have a clean installation.
It would be possible to embed the File as a resource, but then you would
have the problem that if you extract the file temporarily to display it, you can't really control the clean-up of that file, because it's locked by the PDF Reader Application.
So you would end up with the PDF File anyway ;)
What you can do to keep your Application Folder cleaner, is to not install the PDF under that Application Folder but under the "Common Documents" Directory.
For Example: Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), "MySoftware", "Help.pdf")
Which normally targets: C:\Users\Public\Documents\MySoftware\Help.pdf

C# Xml files when creating exe application

I'm planning to build my winform into a .exe file. I'm just wondering what to do with the XML files that my application needs?
I did some research and found out that I can add the XML files in the Resource folder before creating a .exe file.
Or I need to create a setup file? When the user runs the setup file, the XML files will be installed into their pc.Now I wonder which one is the best way to go for,
Note: XML files might get modified by the user.
If you want to ship the XML files as seperate to the .EXE then you can set the Copy to Output Directory to Copy if newer. (click on file and then go to properties).
OR if you want it as part of the .EXE I think you can change the Build Action to Embedded Resource.
I personally would create a Setup as per your edit and include the XML files. I usually just add everthing from the bin/release folder that is needed when I create a setup file.
You could either deploy the necessary files along with the executable in the same folder or embed them as resources (if they are read-only). If you need to modify them do not embed them as resources into the executable.
The correct way depends on how you intend to use the files. If the files always are deployed together with your application, the application never writes to them and they are never upgraded without upgrading the application, you can go with them embedded as resources.
If you need to update them separately from the application, you need to have them as physical files.
You don't necessarely need a installation package, unless you need to apply some logic during setup, such as updating the content of the setup based on user input or to check preconditions. The application can just be copied into place regardless of if you have embedded the files or not.

How to Use a Windows App with Embeded files and folders to copy to a destination?

I am trying to write a small application, whose only purpose is to copy some folders and .cs source files into a user specified Directory, I can do it easy enough by simply having the application look for the files and folders in its own install directory then copy them to thier destination Directory, but I was wondering if its possible to Embed the Folders and Files into the Application, so that when you run the application it creates or copies the folders and files from the exe app directly to the install directory, rather than searching for them in the apps install directory then copying them over. Basically Im trying to only have a single exe file rather than having an exe file and a bunch of folders and files along side it.
Is this possible to do with just a Windows Form App without using an actual Installer Class?
Yes. Embed the files into the application executable as embedded resources. Then when your application runs, access the embedded files and write them to disk in the desired directory structure.
Here is an example of how to embed and access embedded resources from your application assembly.
http://support.microsoft.com/kb/319292
Sure you can, use the BuildAction property as Content or Resource.
Depending on the number and structure of files/folders, you may also consider embedding one zip file and extracting it with sharpziplib or some such.

pack xml files inside dll,c#

I have a .NET C# 2.0 Project and it refers to many .xml files, i'd need these files when i port my project to another location or distribute it. I'm currently not interested in making it as a setup.exe file. I want to to be standalone. currently i've got all of them in a folder "FILES" within my project. So what i want to know is
Can i pack all these XML files inside a dll, so that it's secure and portable? If so how to do it?
When i build the program the FILES folder is not copied. How can i make it copy it as well?
You can mark the xml files as resources, and they will be packaged inside the assembly. Just set the "build action" to "embedded resource". Alternatively, use a resource file (resx), and drag the xml files onto the resx designer, and it'll do everything for you (including providing access methods to get the data back out).

Categories