Home c# Creating a file

Creating a file




Hello everyone.

I want to know how to press the Create file button, for example, (.txt) on C # (Windows Form).

Answer 1, Authority 100%

using system.io;
if (! file.xists (Path)) file.create (PATH);

p.s. In the same namespace there is a class of Directory for similar operations

transferred from the comment.

If you need to create a file with the text

  1. Check the existence of the file and if not, then create it
  2. If you want to write to a file – use Streamwriter

Sample code for writing text to file

string path = "";
if (! file.xists (Path)) file.create (PATH);
Streamwriter Output = New Streamwriter (PATH);
Output.WriteLine (Text);
Output.Close ();

Answer 2

without problems))

system.io.file.writeAllText (Path, Text, [Encoding])

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions