I have created an asp.net form in vb.net that sends an activation email after it is filled out and I was wondering how to attach a file(s) to the activation email sent out after the form is submitted.
The function I believe to use after the 'mail.body' portion is:
Dim attachment as New MailAttachment(Server.MapPath("test.txt"))
mail.attachments.add(attachment)
The portion that is confusing me is what parts above need to be filled in with an actual value. Also, do I need to store the files in a location such as an FTP client or db (at the moment they are on my hardrive).
If the file (in this case the file is a .tar) is placed in a folder within a folder would the highlighted portion look like this:
Dim attachment as New MailAttachment(Server.MapPath("VDI") & "/" & "SMB" "/" "license.tar")
mail.attachments.add(attachment)
In this case I am using the FTP filezilla client for the website to upload files, do I route every folder from the start folder to the actual file? (basically the folder mapping has gotten me confused).
In this case I am using the FTP filezilla client for the website to upload files, do I route every folder from the start folder to the actual file? (basically the folder mapping has gotten me confused).
I'm not very sure about your issue. If you upload your file to server. Just use Server.MapPath to get the file on server and then use the MailAttachment to attach the file to MailMassage object.
If you have some issue of getting file from directory. You can use
DirectoryInfo and
FileInfo to find and manipulate file on server.
cyvarza
Member
2 Points
3 Posts
How to attach files in vb.net
Mar 30, 2011 06:31 PM|LINK
Hi everybody,
I have created an asp.net form in vb.net that sends an activation email after it is filled out and I was wondering how to attach a file(s) to the activation email sent out after the form is submitted.
The function I believe to use after the 'mail.body' portion is:
Dim attachment as New MailAttachment(Server.MapPath("test.txt"))
mail.attachments.add(attachment)
The portion that is confusing me is what parts above need to be filled in with an actual value. Also, do I need to store the files in a location such as an FTP client or db (at the moment they are on my hardrive).
kedarrkulkar...
All-Star
34247 Points
5505 Posts
Re: How to attach files in vb.net
Mar 30, 2011 07:33 PM|LINK
suppose u have text file test.txt which u want to send with activation mail...
create a folder in u r website named "MailAttachment". put the text file inside this folder
then, u r code will look like this
Dim attachment as New MailAttachment(Server.MapPath("MailAttachment") & "/" & "test.txt")
mail.attachments.add(attachment)
the higlighted part in above code indicate path of file u want to attach.... u can directly refer to file stored on server.
hope this helps....
KK
Please mark as Answer if post helps in resolving your issue
My Site
cyvarza
Member
2 Points
3 Posts
Re: How to attach files in vb.net
Mar 30, 2011 08:15 PM|LINK
Thank you very much for the help!
If the file (in this case the file is a .tar) is placed in a folder within a folder would the highlighted portion look like this:
Dim attachment as New MailAttachment(Server.MapPath("VDI") & "/" & "SMB" "/" "license.tar")
mail.attachments.add(attachment)
In this case I am using the FTP filezilla client for the website to upload files, do I route every folder from the start folder to the actual file? (basically the folder mapping has gotten me confused).
Thank you!
Zizhuoye Che...
All-Star
21915 Points
1915 Posts
Re: How to attach files in vb.net
Apr 04, 2011 02:23 AM|LINK
Hi,
I'm not very sure about your issue. If you upload your file to server. Just use Server.MapPath to get the file on server and then use the MailAttachment to attach the file to MailMassage object.
If you have some issue of getting file from directory. You can use DirectoryInfo and FileInfo to find and manipulate file on server.
http://csharp.net-tutorials.com/file-handling/file-and-directory-information/
Hope this can help you.
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework