C # winForms Output to a text file

I am using C # windows Forms in visual studio 2010.

I need to know what is the best way to output the data that was selected in winForm to a simple text file, please?

Example:

User must select time / date. as soon as the user selects it, press the confirmation button.

I need a confirmation button in winForm to send a date / time to a txt file that is saved on a computer in a specific place.

Any help in this area would be greatly appreciated!

+3
source share
2 answers

Use System.IO.StreamWriter.

As an example:

System.IO.StreamWriter writer = new System.IO.StreamWriter("path to file"); //open the file for writing.
writer.Write(DateTime.Now.ToString()); //write the current date to the file. change this with your date or something.
writer.Close(); //remember to close the file again.
writer.Dispose(); //remember to dispose it from the memory.

, , UAC ( ) . , , , .

, . ( ) ... , .

( % localappdata% "" ). UAC . ; .

:

string path = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

, .

+5

...

String YourFormattedText = FieldFromForm.ToString( whatever formatting );
File.WriteAllText( FullPathAndFileNameToWriteTo, YourFormattedText );
+2

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


All Articles