0

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("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) 
Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • Show the code you want to use to send the e-mail message. – Joel Coehoorn Jan 16 '15 at 03:50
  • I see two text file attachments. Are these already on the file system, or are you trying to figure out how to create them. Where does the data for the excel attachment come from? – Joel Coehoorn Jan 16 '15 at 04:08
  • I generate the excel format document by the response.addheader coding the FileA and FileB only my testing file to test the code really can send the email with real attachment.but i want to generate the excel to the server(where the program source code location), because sending email coding only can find the local directory for the attachment. it is not possible if the excel dowload to the client side, and i still want the program can use the excel to be the email attachment – Small Programto Jan 16 '15 at 07:10

0 Answers0