maybe another program uses the files and then the above error occurs.
To see if you can have exclusive access to the file you can use this class:
public class FileCheck
{
public static Boolean FileCanBeCopied(String FolderAndFileName)
{
Boolean canBeCopied = false;
if (!String.IsNullOrEmpty(FolderAndFileName))
{
FileInfo fi = new FileInfo(FolderAndFileName);
if (fi.Exists)
{
FileStream stream = null;
try
{
using (stream = File.Open(FolderAndFileName, FileMode.Open, FileAccess.Write, FileShare.None))
{
if (stream.CanWrite)
canBeCopied = true;
}
}
catch (Exception)
{
canBeCopied = false;
}
}
}
return canBeCopied;
}
}