I'm new to C# and VS, and I have a bizarre problem.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ExampleApplication {
class Program {
static void Main(string[] args) {
FileInfo fi = new FileInfo("C:\\TEST.TXT");
fi.Create();
Console.WriteLine("File exists: {0}", fi.Exists);
}
}
}
This is my program, it creates a file TEST.TXT. When I run the program inside VS 2010 with the Debug -> Start Debugging command (F5), the program works fine and the file is created.
However if I build the solution then run the program from the .exe using cmd prompt:
C:\...\Visual Studio 2010\Projects\ExampleApplication\ExampleApplication\bin\Debug\ExampleApplication.exe
It runs outputting: File exists: true. But the file is not created. Anyone have any ideas?
Thanks
Perhaps file stream eventually was not released by OS so file system does not reflect recent changes? Just try explicitly closing a new file stream after creation:
FileInfo fi = new FileInfo("C:\\TEST.TXT");
using (var stream = fi.Create());
Please let us know whether it works or not since it is a bit crazy idea ;) I believe problem could be even simple
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With