dimensionav
asked on
How to attach a file with a form data ?
HI
I would like to send the data from a form by mail (this is not a big deal) but in the form will be a field that will ask for a PDF file in order to "attach it" to the message, considering that I wonder the following:
1. I need the code for attach the file to an email, I use System.Net.Mail.MailMessag e for that purpose with an special function (please see below code area).
2. Would be possible that each time that somebody sends a messages, part of the code make a clean up in order to avoid have stored alot of PDF files in the server ?
3. Would be possible to protect the selection of the file for only PDF files ?
Thanks in advance.
I would like to send the data from a form by mail (this is not a big deal) but in the form will be a field that will ask for a PDF file in order to "attach it" to the message, considering that I wonder the following:
1. I need the code for attach the file to an email, I use System.Net.Mail.MailMessag
2. Would be possible that each time that somebody sends a messages, part of the code make a clean up in order to avoid have stored alot of PDF files in the server ?
3. Would be possible to protect the selection of the file for only PDF files ?
Thanks in advance.
' This is how I call de function
Dim Messagebody As String = ScreenScrapeHtml("http://www.mydomain.com.mx/contact_body_message.aspx?Email=" & tbEmail.Text & "&Name=" & tbName.Text & "&Address=" & tbAddress.Text & "&Subject=" & ddlSubject.SelectedValue & "&Comments=" & tbComments.Text)
'This is the funcion
Public Function ScreenScrapeHtml(ByVal url As String) As String
Dim objRequest As Net.WebRequest = System.Net.HttpWebRequest.Create(url)
Dim sr As New IO.StreamReader(objRequest.GetResponse().GetResponseStream())
Dim result As String = sr.ReadToEnd()
sr.Close()
Return result
End Function 'ScreenScrapeHtml
1) Mailmsg.Attachments.Add(Ne w Attachment("filepath")
2) You can File.Delete(filename) after sending the mail message.
3) If the file is uploaded from the client side, you need to perform the validation on the server. Use the IO.Path.GetExtension method to get the extension and compare with .pdf
2) You can File.Delete(filename) after sending the mail message.
3) If the file is uploaded from the client side, you need to perform the validation on the server. Use the IO.Path.GetExtension method to get the extension and compare with .pdf
ASKER
I´ve been reading your documentation, I just have a doubt, How to get the file path from the client machine, which controls and objects?
Thanks!
Thanks!
ASKER
I asked that because I have understood that the attached file will never be stored on the hosting server, am I right?
>I have understood that the attached file will never be stored on the hosting server
The file is being uploaded from the client? It will have to be stored on the server somewhere even though it would be temporary.
The file is being uploaded from the client? It will have to be stored on the server somewhere even though it would be temporary.
ASKER
Ok, in that case I shouldn´t be concerned about how to delet it, right?
Depends on your application. You should usually delete these files.
ASKER
Thanks CodeCruiser, finally could you tell me how to get the client path and name of the file that will be attached ?
Thanks for everything
Thanks for everything
Try This,
Dim atch as Attachment = New Attachment(Server.MapPath( "Somefile. dat"))
Msg.Attachments.Add(atch)
Dim atch as Attachment = New Attachment(Server.MapPath(
Msg.Attachments.Add(atch)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have a form that collects all data that will be sent (Name, Company, etc.) even the file that will be attached, do I have to use FileUpload control in order to get the file name from client?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://msdn.microsoft.com/en-us/library/system.net.mail.attachment.aspx
http://www.systemnetmail.com/
http://www.systemwebmail.com/faq/2.3.aspx