I'm using Response.AddHeader
to generate an Excel file. This works fine if I want to send the file to the user's browser as a download.
Is it possible to use Response.AddHeader
to save the file to directory on the server? I need to send to send the file as an attachment to an email message, and i can't find any way to generate the file on the server side.
Here is the code i use to change my html page to the excel format for the user download:
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
Here is the send mail code
Dim myMail As New MailMessage()
myMail.From = New MailAddress("[email protected]", "Sam Wong W")
myMail.To.Add("[email protected]")
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)