Ben Bodie
Ben Bodie

Reputation: 75

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.

Upvotes: 0

Views: 347

Answers (1)

Patrick
Patrick

Reputation: 419

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.

Upvotes: 3

Related Questions