A
avivgood
Guest
I am trying to Save file - delete the old file, and replace it with a new one that has newer data. when I try to delete the old file and replace it with new one:
private void Save()
{
File.Delete(path); //<---- Error here
var b = new BinaryFormatter();
using (var st = new FileStream(path, FileMode.Create, FileAccess.ReadWrite))
b.Serialize(st, Tree);
}
I get an error: System.UnauthorizedAccessException:Access to path (path) denied
How can I delete the file?
(Here is the code from when I'm creating the file, if you believe the error is there(
var SerializeStream = new FileStream(FilePath + @"\" + Project_Name + ".bin", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
Formatter.Serialize(SerializeStream, NewEmployeeTree);
SerializeStream.Close();
Continue reading...
private void Save()
{
File.Delete(path); //<---- Error here
var b = new BinaryFormatter();
using (var st = new FileStream(path, FileMode.Create, FileAccess.ReadWrite))
b.Serialize(st, Tree);
}
I get an error: System.UnauthorizedAccessException:Access to path (path) denied
How can I delete the file?
(Here is the code from when I'm creating the file, if you believe the error is there(
var SerializeStream = new FileStream(FilePath + @"\" + Project_Name + ".bin", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
Formatter.Serialize(SerializeStream, NewEmployeeTree);
SerializeStream.Close();
Continue reading...