3

Hi I am recently using Visual Studio 2008. My problem is I already added a text file into my project [''add new items\general\Text File''].[Is not it a embedded data like icon file or background image file ?] I want to store some data into it. But dont know how to open this file. Please any opinion will be very helpful. Thanks.

Barun
  • 1,837
  • 3
  • 27
  • 46
  • possible duplicate of [How to read embedded resource text file](http://stackoverflow.com/questions/3314140/how-to-read-embedded-resource-text-file) – Martin Liversage Aug 07 '10 at 12:01

1 Answers1

4

Either place the file at some place (eg relative to .EXE) that you can reconstruct at runtime and open it.

Another approach is to add it to your resources.

If you want to read and write it, you'll have to pick another place, like Application.UserAppDataPath.


In the Menu, select Project|Properties|Resources.
On the resources page, select "Add existing File" and pick your textfile. It will get a simplified name (like TextFile1) that is a valid C# identifier.

In your code, you can get the contents with

 string s = Properties.Resources.TextFile1;
Henk Holterman
  • 250,905
  • 30
  • 306
  • 490