C# – How to create directories

You can use Directory.CreateDirectory() to create a directory at the specified path (absolute or relative), like this: This creates the directory if it doesn’t exist, otherwise it does nothing. That means you don’t need to check if the directory exists before calling Directory.CreateDirectory(). In this article, I’ll go into more details about using Directory.CreateDirectory(). CreateDirectory() … Read more

C# – How to create a file and write to it

There are a few ways to create a file and write to it using the .NET File API (in System.IO). The simplest way is to use high-level methods like File.WriteAllText() and File.WriteAllLines(), specifying the file path and string(s) to write to the file. Here’s an example of using these (and their async equivalents): These high-level … Read more