how can I embed a file into an exe?

前端 未结 1 1850
春和景丽
春和景丽 2021-01-03 09:43

I need to have a file containing my data embedded into an exe so when the users call it it will open the file, read it, take action and for the users to not see this file or

相关标签:
1条回答
  • 2021-01-03 10:14

    Double-click your Properties node in projects

    enter image description here

    Click Resources, then click the link to create a resources file

    enter image description here

    Click "Add Resource" and select "Add an existing file". This adds the file to your resources.

    enter image description here

    The file is added as a public static property of the Resources class that can be accessed by the name given it. in the example, I've added an xml file called "SampleConfiguration". I can access it within code by the following:

    var fileString = ActivityLibrary1.Properties.Resources.SampleConfiguration;
    

    Where ActivityLibrary1 is the default namespace of the assembly. As the file was a text file, it was added as a string resource. If you add a binary file, it will be added as a byte array. How to deal with files in byte arrays is another question...

    0 讨论(0)
提交回复
热议问题