After copying the file to a temporary directory, I cannot delete the copy due to a UnauthorizedAccessException . The idea here is to get a copy of the file, zip it, and then delete the copy, but after deleting all the code between File.Copy and File.Delete I still get the exception. Exiting the program releases the lock and allows me to delete the copy without any problems.
Is there a way to copy without this persistent lock (and save file metadata like LastModified)? Or a way to free the castle? Should there be a lock on the copied file after the completion of File.Copy ?
I am using Visual C # 2010 SP1 for the .NET Framework 4.0.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO; using System.Xml; namespace Test { class Program { static void Main(string[] args) { String FileName = "C:\\test.txt";
source share