Wednesday, August 12, 2009

File Permissions Problem

We were having errors trying to move a file. The source file was occasionally “Read-only” and cannot be overwritten or deleted. To avoid this problem before we used the Delete() or CopyTo() methods of the System.IO.FileInfo class.

System.IO.FileInfo fi = new System.IO.FileInfo(fileName);
fileInfo.IsReadOnly = false;