It can be as
simple as this:
using System.IO;
namespace WFTemplate_Aug2020
{
public static class public_static_class_FileExtensions
{
public static FileStream NewFile(this string folderpath, string filename, string extension)
{
return File.Create($"{folderpath}{filename}{extension}");
}
}
}
Sample call:
FileStream fs = @"C:\Users\test_user\Desktop\New Stuff\".NewFile("xray", ".txt");
However:
0 this code will write over an existing file with the same name and path
1 this code will not intercept possible errors in file access like 'permission denied, or the file existing and being read-only.
2 there's no checking here for the easy to make mistakes in using // file path separators, and no checking for existing valid directory structure names.
See the other possible exceptions here: [
^]
"Real world code" requires you address these concerns !
The other answers here show you how to check for a Directory existing.