简体   繁体   中英

C# Embed File Programmatically

I have a requirement where I want a user to select a file and it will embed it into my application

I know how to embed a resource manually, however I don't know if there is a way to do it programmatically when the user selects a file.

If you mean actually embed data into your 'application.exe', this is not possible without a second executable to perform the operation. The operating system puts a lock on a running executable, to prevent modifications like this.

If you 100% did want to store data in your executable, it would have to be right at the end of the file. I've tried just dumping some random binary data into the end of an executable, and it seemed to run just fine, but there's probably consequences.

What you should probably be doing instead is create and manage a folder on the user's machine -- maybe directly on the hard drive, on their user account, online, or in a folder they choose -- and store files there. Then, load them when needed.

This approach works for all resources. Please specify the resources you are wanting to 'embed' -- and why other approaches are unsuitable -- for better help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM