Reputation: 129
i have to write file on perticuler path of c drive i used following code it is givin above error The given path's format is not supported.
My path Value is D:\Ea\10\rep\Demo.txt
System.IO.File.WriteAllText(path, string.Empty);
StreamWriter file2 = new StreamWriter(path, true);
file2.WriteLine("Demo");
file2.Close();
if (System.IO.File.Exists(path))
System.IO.File.Copy(path, @"D:\Demo.htm", true);
Upvotes: 0
Views: 1664
Reputation: 26209
I think there is no problem in the code but if your StreamWriter
is not disposed properly then you need to face some issues.so it is good to move your StreamWriter
inside using{}
block so StreamWriter
willbe disposed as soon as it finishes the Writing.
Try This:
String path=@"D:\Ed\10\rep\Demo.txt";
System.IO.File.WriteAllText(path, string.Empty);
using (StreamWriter file2 = new StreamWriter(path, true))
{
file2.WriteLine("Demo");
}
if (System.IO.File.Exists(path))
System.IO.File.Copy(path, @"D:\Demo.htm", true);
Upvotes: 1
Reputation: 2557
System.IO.File.WriteAllText(path, string.Empty);
You wouldn't append a @ symbol to the path. You should be able to just put in the path value (depending on what it is).
E: You just said in your comments its D:\Ea\10\rep\Demo.txt , but the error is 'D:\ED\10\Res\Demo.txt' is denied? Maybe its because the file names are a bit off? trying changing the path value
Upvotes: 2