I get this error when trying to create a file using Filestream in C#.
When i use :
{
string loc1 = @"C:\Users\www14\AiLog\Fitness:200.txt";
FileInfo fi = new FileInfo(loc1);
using (FileStream fs = fi.Create())
}
File in a directory : C:\Users\www14\AiLog\Fitness:200.txt is succesfully created , and appears.
However, i need this number 200 to be a variable, not a handwritten number, so i tried following :
string loc1 = @"C:\Users\www14\AiLog\";
string loc3 ="Fitness:"+BestNetworkFitness.ToString()+".txt";
string loc2 = Path.Combine(loc1, loc3);
FileInfo fi = new FileInfo(loc2);
using (FileStream fs = fi.Create())
{ }
Then DirectoryNotFoundException: Could not find a part of the path "C:\Users\www14\AiLog\Fitness:3.73398.txt".
It seems like whenever i try to use a variable in a name, it breaks.
EDIT : oh thanks for pointing out , my loc1, loc2 was messed up. Also i deleted the ':' and it works now !