Last post Oct 29, 2010 08:32 PM by mikediazpr
Oct 27, 2010 11:18 PM|mikediazpr|LINK
I need some advice on what to use for adding multiple attachment to a email. I'm using VB 2010.
First, I have a Form in my company web site to fill a reclamation ..... when you fill and send it, it convert the form into a PDF, save it in the client side "TEMP" and finally get the PDF and send it to a email..... that's perfectly fine. I add to the
form the capability of attach multiple files with file upload to the same "TEMP" and displayed in a Grid View to remove or add files and send everything to a email, the attachment capability is working. Everything is working with the PDF not the files(attachments).
There is a way to get the multiple files from the "TEMP" folder and add it to some dynamically variable (array list, attachment collection, list collection, etc.) so all can be send to the email. I already know the way to put it into the email with the PDF.
The problem is to get the files and add it to the dynamic variable and that it work with the email.
If the code is need it, let me know.
Oct 28, 2010 05:31 AM|ignatandrei|LINK
I already know the way to put it into the email with the PDF. The problem is to get the files and add it to the dynamic variable and that it work with the email.
Fi you know how to put 1 file, find all files by Directory.GetFiles
Oct 28, 2010 02:02 PM|mikediazpr|LINK
I’m gething the PDF directly by a path in a string variable:
AttFile = PdfTempFolder & "Temp\FormaLiabilityMunicipios" & Session.SessionID & ".pdf"
Then put it in here:
If File.Exists(AttFile) = True Then
EmailCls.CreateMessageWithAttch(AttFile, EmailAsunto, ToEmail, CCEmail, EmailMessage)
Me.EmailCopiaTextBox.Text = ""
Me.PnlDescarga.Visible = True
Me.DescargaLnk.NavigateUrl = UrlPath
I’m looking for some way to use the Dyrectory.GetFiles(PdfTempFolder & "\Temp\") for each one of the files and put it in a variable defined as:
Dim attach_items As Net.Mail.AttachmentCollection so I can use it like this:
EmailCls.CreateMessageWithAttch(AttFile, attach_items, EmailAsunto, ToEmail, CCEmail, EmailMessage)
And send every file in the AttachmentCollection.
Thanks for your help.
Oct 28, 2010 02:10 PM|ignatandrei|LINK
to have the AttFile not string , but List<string>
then List<string> attfiles =new List<string>();
foreach(string FileName in Dyrectory.GetFiles(PdfTempFolder & "\Temp\*.pdf"))
EmailCls.CreateMessageWithAttch(attfiles, EmailAsunto, ToEmail, CCEmail, EmailMessage)
Please see in CreateMessageWithAttch how you attach the AttFile and then use a foreach to attach the
Oct 28, 2010 09:01 PM|mikediazpr|LINK
I use your advice to create a function. I need to made a full test, but my email is not working. This is the function.
Function add_attachment() As Boolean
Dim Email As New MailMessage
Dim files() As String = Directory.GetFiles(PdfTempFolder & "\TEMP\")
Dim attach_item As String
If files.Length > 0 Then
For i As Integer = 0 To files.Length - 1
attach_item = files(i).ToString
Oct 28, 2010 09:12 PM|ignatandrei|LINK
Why is not working ? There is some error ? ?
Oct 29, 2010 06:19 PM|mikediazpr|LINK
When i debug to made a test, fill the pdf and add the attachments to send the email. I do not receive the email. Everything is working the pdf and the attachments. I don't know if there is another way to make the test. I check the Path, the PDF and the attachments
are there. but not receive the email. I have to find out because i didn't touch the email part (code).
Tanks for all your help.
Oct 29, 2010 07:24 PM|ignatandrei|LINK
1. try removing the new code, put the old with 1 pdf. Does it work?
2. try modifying the project and , from the list, put only the first attachment. Does it work?
3. try modifying the project and , from the list, put all attachments. Does it work?
Oct 29, 2010 08:32 PM|mikediazpr|LINK
The problem was a Try , Catch exception when it construct the email. I fix it. Alll the attachments and the pdf are on the server path temp, there is a way to delete all the files and the temp directory when it finaly send it. I was trying but i get the
error that it can access the file because another process was using it.