PANKAJ 786
PANKAJ 786

Reputation: 129

The given path's format is not supported. when passing path what kind of path we have to pass

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

Answers (2)

Sudhakar Tillapudi
Sudhakar Tillapudi

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

Dylan Corriveau
Dylan Corriveau

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

Related Questions