string status = Emailer.SendMessageWithAttachment(sendTo, sendFrom, sendSubject, sendMsgBody, sendAttachments);
if (status.Equals("101"))
{
//System.Threading.Thread.Sleep(50000);
System.DateTime dt = System.DateTime.Now + new TimeSpan(0, 5, 0);
foreach (string strFile in sendAttachments)
{
try
{
string strFileName = strFile.Substring(strFile.LastIndexOf('\\'));
//while (FileInUse(strFile))
//{
// Thread.Sleep(1000);
// if (dt < System.DateTime.Now)
// {
// MyMessageBox.ShowBox("Original report files not moved to sent items.", "Email Status", MyMessageBox.MyMessageBoxButton.OK, MyMessageBox.MyMessageBoxIcon.Information);
// return;
// }
//}
File.Move(strFile, LocalResources.processedInfoDirectory + "Sent Mails" + strFileName);
}
catch (Exception ex)
{
MyMessageBox.ShowBox("Error in moving file due to " + ex.Message, "Error", MyMessageBox.MyMessageBoxButton.OK, MyMessageBox.MyMessageBoxIcon.Error);
}
}
status = "Old De-identification status reports successfully sent to " + sendTo + " at " + System.DateTime.Now.ToString() + ".";
MyMessageBox.ShowBox(status, "Email Status", MyMessageBox.MyMessageBoxButton.OK, MyMessageBox.MyMessageBoxIcon.Information);
}
else
{
MyMessageBox.ShowBox(status, "Email Status", MyMessageBox.MyMessageBoxButton.YesNo, MyMessageBox.MyMessageBoxIcon.Error);
}
}
static bool FileInUse(string path)
{
try
{
//Just opening the file as open/create
using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate))
{
//If required we can check for read/write by using fs.CanRead or fs.CanWrite
}
return false;
}
catch (IOException ex)
{
//check if message is for a File IO
if (ex.Message.ToString().Contains("The process cannot access the file"))
return true;
else
throw;
}
}