This will send an email when a button gets pushed. However I am trying to call the FileResult, SaveDocument, to download a file right before redirecting back to the button page.
I am using a hardcoded file for now to download for the sake of testing. I can run the SaveDocument() result using a test button. I can't send an email, run the SaveDocument Action and then redirect.
[HttpGet]
public ActionResult send(int thisbatch, string listofpositives)
{
MailMessage mail = new MailMessage();
SmtpClient smtpServer = new SmtpClient("smtperServer");
smtpServer.Port = 25; // Gmail works on this port
smtpServer.EnableSsl = false;
mail.From = new MailAddress("xxxe@xxx.com");
mail.To.Add("xxxe@xxx.com");
mail.Subject = "Batch Closed";
mail.Body="some info stuff here";
smtpServer.Send(mail);
SaveDocument();
return RedirectToAction("AddColiform");
}
//THIS WORKS BY ITSELF CALLED FROM A BUTTON
public FileResult SaveDocument()
{
string filePath = Server.MapPath("~/XML_positives/Test1.xml");
string contentType = "text/xml";
return File(filePath, contentType, "Test1.xml");
}