Text file for storing data

I want to save some data in a text file in my C # application. I added a text file to the root of my project.

How do I access it now? Will this file be embedded in my exe or what?

+3
source share
5 answers

First, make sure you right-click the file and select Copy to Output Directory.

Secondly, the file will not be embedded in the executable file. This will be a regular * .txt file along with your * .exe, and you will get access to it as such:

StreamWriter sw = null;
FileInfo fi = new FileInfo(Path.Combine(Application.StartupPath, "filename.txt"));

if(fi.Exists)
    sw = new StreamWriter(fi.Open(FileMode.Open));
+6
source
  • You need to install the file to copy to the output directory.
  • ( "file.txt" ".file.txt" )

exe.

.

+2

, exe, , StreamWriter w/e, .

0

, "" , , , . a > . MSDN:

0

There's also a great Nini project ( http://nini.sourceforge.net/manual.php ) that makes it easy to access (and write) simple configuration files of different tastes and possibly combine them with command line options.

0
source

Source: https://habr.com/ru/post/1756805/


All Articles