I am stuck at this exception. I am not sure, which part of my code could be blocking the xml file.
This is main.cs:
foreach (var po_no in DatabaseData.getPO_NOs())
{
XmlFile.serialize(DatabaseData.read(po_no));
}
foreach (var fileToSend in new DirectoryInfo(AppD_Config.getConfigKey("toSendFolder")).GetFiles())
{
Mail.Mail.send("xxxx", "xxxx", fileToSend.FullName.Split('\\').Last(), " ", fileToSend.FullName);
Debug.WriteLine("Sent mail.");
fileToSend.MoveTo(fileToSend.FullName.Replace(AppD_Config.getConfigKey("toSendFolder"), AppD_Config.getConfigKey("sentFolder")));
//EXCEPTION OCCURS RIGHT UP THIS COMMENT------------------
}
XmlFile.serialize-
public static string serialize(Order order)
{
Directory.CreateDirectory(AppD_Config.getConfigKey("toSendFolder"));
string fullPath = AppD_Config.getConfigKey("toSendFolder") + order.PO_NO + @"_epce_PO.xml";
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("structure", "ORDERS");
ns.Add("orders_structure_ver", "1");
var serializer = new XmlSerializer(order.GetType());
using (TextWriter writer = new StreamWriter(fullPath))
{
serializer.Serialize(writer, order, ns);
writer.Close();
return fullPath;
}
}
Mail.Send-
public static void send(string from, string to, string subject, string message, string attachmentPath)
{
MailMessage mail = new MailMessage(from, to);
SmtpClient client = new SmtpClient();
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Host = "smtpexch";
client.Port = 25;
mail.Attachments.Add(new Attachment(attachmentPath));
mail.Subject = subject;
mail.Body = message;
client.Send(mail);
}
I am honestle not able to find, what is causing the file block. This should be all the code, that has to do something with the file.
Everything else is just not touching the code. I can add anything else if you would find any method disturbing.
Thanks in advance.
EDIT_THE EXCEPTION
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: The process cannot access the file because it is being used by another process.