How do I create directory if it doesn’t exist to create a file?

I have a piece of code here that breaks if the directory doesn’t exist:

System.IO.File.WriteAllText(filePath, content);

In one line (or a few lines), is it possible to check if the directory leading to the new file doesn’t exist and if not, to create it before creating the new file?

I’m using .NET 3.5.

6 Answers
6

Leave a Comment