Actually i want to copy file from one folder to another folder,but before copying file i have to check same file is exists in destination folder,if it exists first i have to delete that file and then copy new file to destination folder.
but i am getting unauthorized exception in server.i am thing this error is because of
i am deleting file when that is in use,but i donot know excatly whats happening.
string filename = "file1.txt";
string filename1 = "file1Copy.txt";
string filesource = Server.MapPath("~/Lucky/") + filename;
string destinationFile = Server.MapPath("~/LuckyCopy/") + filename1;
if (System.IO.File.Exists(destinationFile))
{
System.IO.File.SetAttributes(destinationFile, FileAttributes.Normal);
System.IO.File.Delete(destinationFile);
}
System.IO.File.Copy(filesource, destinationFile, true);
System.IO.File.SetAttributes(destinationFile, FileAttributes.Normal);
What I have tried:
i have tried like
string filename = "file1.txt";
string filename1 = "file1Copy.txt";
string filesource = Server.MapPath("~/Lucky/") + filename;
string destinationFile = Server.MapPath("~/LuckyCopy/") + filename1;
if (System.IO.File.Exists(destinationFile))
{
System.IO.File.SetAttributes(destinationFile, FileAttributes.Normal);
System.IO.File.Delete(destinationFile);
}
System.IO.File.Copy(filesource, destinationFile, true);
System.IO.File.SetAttributes(destinationFile, FileAttributes.Normal);