0

Response.AddHeader用来生成 Excel 文件。如果我想将文件作为下载发送到用户的浏览器,这可以正常工作。

是否可以使用Response.AddHeader将文件保存到服务器上的目录?我需要发送以将文件作为电子邮件的附件发送,但我找不到在服务器端生成文件的任何方法。

这是我用来将我的 html 页面更改为 excel 格式以供用户下载的代码:

Try
    Response.Clear()
    Response.Buffer = True
    Response.AddHeader("content-disposition", "attachment;filename=" + fileName)
    Response.Charset = "BIG5"
    Response.ContentType = "application/vnd.ms-excel"

    '...   

Catch ex As Exception

End Try

这是发送邮件代码

 Dim myMail As New MailMessage()
    myMail.From = New MailAddress("samwong2@gmail.com", "Sam Wong W") 
    myMail.To.Add("SYWongW@gmail.com")





    myMail.SubjectEncoding = Encoding.UTF8  
    myMail.Subject = "testing"
    myMail.IsBodyHtml = True    
    myMail.BodyEncoding = Encoding.UTF8
    myMail.Body = "TEST123" 
    myMail.Attachments.Add(New System.Net.Mail.Attachment("C:\FileA.txt"))  
    myMail.Attachments.Add(New System.Net.Mail.Attachment("C:\FileB.txt"))
    Dim mySmtp As New SmtpClient()  
        mySmtp.Port = 25   'SMTP Port 
    mySmtp.Host = "smtphost"  
    mySmtp.EnableSsl = False 
    mySmtp.Send(myMail) 
4

0 回答 0