Answers for "c# how to create a new file with a random string name"

C#
1

c# how to create a new file with a random string name

// How to create a new .txt file with a random string name: 
// selected characters
string chars = "2346789ABCDEFGHJKLMNPQRTUVWXYZabcdefghjkmnpqrtuvwxyz";
// create random generator
Random rnd = new Random();
string name;
do {
   // create name
   name = string.Empty;
   while (name.Length < 5) {
      name += chars.Substring(rnd.Next(chars.Length), 1);
   }
   // add extension
   name += ".txt";
   // check against files in the folder
} while (File.Exists(Path.Compbine(folderPath, name)))
Posted by: Guest on August-30-2020

Code answers related to "c# how to create a new file with a random string name"

C# Answers by Framework

Browse Popular Code Answers by Language