我正在创建一个Web应用程序,允许我的用户编辑像gridview一样的excel。
我合并了两个按钮,它们会发送一封附有excel文件的电子邮件,还会显示一个显示正在发送的excel文件的按钮。
两者的问题在于,在请求只查看文件时,它在本地显示正常但在推送到我的Web服务器时它根本不起作用。
使用另一个按钮将文件作为附件发送到电子邮件中,它将不会附加,但会发送电子邮件。
这是发送电子邮件的代码:
try
{
const string attachment = "summary.xlsx";
var mail = new MailMessage();
mail.To.Add("Tester@test.com");
mail.From = new MailAddress("Tester@test.com");
mail.Subject = "SummarySpreadsheet " + DateTime.Now.ToString("MM-dd-yyyy");
mail.Body = "Hello Everyone," + "\n" + "\n" +
"Attached is the Spreadsheet for your review." + "\n" + "\n" +
"Thank you!" + "\n" + "\n";
mail.Attachments.Add(new Attachment(Server.MapPath("//testserver/apps/testApp/Daily/summary.xlsx")));
var smtpClient = new SmtpClient("test.test.com"); //this is fake
smtpClient.Send(mail);
Response.Write("Email Sent Successfully!");
}
catch (Exception ex)
{
Response.Write("Could not send the email - error" + ex.Message);
}
}
以下是我用来查看电子表格的代码:
System.Diagnostics.Process.Start(@"\\testserver\apps\testApp\Daily\summary.xlsx");
我已经完成了我的研究并找到了很多方法来发送带有附件的电子邮件,但它们在本地工作但是当推送到我的服务器时没有任何作用。我已经复制了dll并确保一切都一致但仍然没有变化。
对此的任何帮助都会很棒。
谢谢
答案 0 :(得分:0)
能够解决我的问题。
关于打开文件客户端,我不得不使用这段代码(我的目的是服务器端):location.href='_summary.xlsx';return false;
关于电子邮件,我使用stream
和File.OpenRead("file location")
来正确发送。