0

I create a class library and added a text file as one of the resource for the project. I use it like this:

    string commandFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"data\vaCommands.txt");

When i release this dll i do not want this text file (data\vaCommands.txt) to be visible for users. Is there a way to compile it to the code? What is the best approach in these situations?

dandan
  • 509
  • 3
  • 8
  • 21
  • 2
    Yes... You have to change it’s _Build Action_ property to _Embedded Resource_. Your way of reading the file does not work anymore. Use this https://stackoverflow.com/questions/3314140/how-to-read-embedded-resource-text-file – Legacy Code Jul 08 '20 at 06:02

1 Answers1

0

try this :

Add file to Resources.resx Open up the Resources.resx file, use the dropdown box to add the file, set Access Modifier to public. enter image description here

then you can get text if file like that:

string text = Properties.Resources.vaCommands;
Ruben Helsloot
  • 12,582
  • 6
  • 26
  • 49
TECNO
  • 162
  • 2
  • 3
  • 15
  • I tried but it only added parts of the file - is there a limit to the # of rows for txt file? In addition I forgot to mention that i keep updating the textfile externally and i need these changes to be reflected in the build. – dandan Jul 08 '20 at 08:19
  • @dandan you can't update embedded files at runtime see this thread :[link](https://stackoverflow.com/questions/12941957/changing-content-in-embedded-resources-file) . if you need anther way , try to encrypt file without embedded it – TECNO Jul 08 '20 at 08:54
  • for max `string` **size** see this : [link](https://stackoverflow.com/questions/140468/what-is-the-maximum-possible-length-of-a-net-string) – TECNO Jul 08 '20 at 08:58
  • 1
    @TENCO I do not want to update the file in runtime. I want to update it before but updating the file is done by excel. I export the text file before the build but i want the changes to be reflated in it – dandan Jul 08 '20 at 16:21
  • I don't know the limitation of size . but yes you can update file that will placed in your_project\Resources folder @dandan – TECNO Jul 08 '20 at 16:45