开发者

c# : How To use a Text File Which added to My project From 'add new items\general'

开发者 https://www.devze.com 2023-01-11 01:59 出处:网络
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

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.


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消