Create Random File
using System.IO;
using System;
class CreateRandomFile
{
static void Main()
{
// Specify a name for your top-level folder.
string folderName = "D://MyFolder";
/* To create a string that specifies the path to a subfolder under your top-level folder, add a name for the subfolder to folderName. */
string pathString = System.IO.Path.Combine(folderName, "NewFolder");
System.IO.Directory.CreateDirectory(pathString); // Creates the directory specified by the pathString.
// Create a random file name for the file you want to create.
string fileName = System.IO.Path.GetRandomFileName();
// We also can specify a particular name for the file.Example: string fileName = "MyNewFile.txt";
// Use Combine again to add the file name to the path.
pathString = System.IO.Path.Combine(pathString, fileName);
FileStream fs = File.Create(pathString); // Creates the file with the specified path.
Console.WriteLine("File Created Successfully");
Console.ReadLine();
}
}
Output:
File Created Successfully