raja
raja

Reputation: 3

asp.net The process cannot access the file with File.Copy and File.Delete

I am using simple File.Copy and File.Delete basically first I copy my file from one folder to another than I call File.Delete to Delete From Previous folder but when compiler comes on File.Delete it give me error of

The process cannot access the file with File.Copy and File.Delete

My code is.

  if (!Directory.Exists(copyPath))
            {
                File.Copy(filefullpath, copyPath);
                File.Delete(filefullpath);
            }

although it copy file into copyPath but delete is giving error.

Upvotes: 0

Views: 370

Answers (2)

Rohan
Rohan

Reputation: 314

Try File.Move

if (!File.Exists(copyPath))
{
     File.Move(filefullpath, copyPath); // Try to move
}

Upvotes: 1

Erik
Erik

Reputation: 119

Isn't this an UnauthorizedAccessException exception? Check if the appropriate users (IIS_IUSRS) have CRUD-rights in the folder. File.Move can cause problems with inheritance of NTFS rights

Upvotes: 0

Related Questions