Hello,
I'm using DotNetNuke.Services.Mail.Mail.SendMail with overload that accept list of system.net.mail.attachment. After successfully sent the email (and received it), I cannot delete files because they are in use. Some minutes later, files can be manually deleted.
Anyone can suggest me a way to "free" them after the email is sent? This is the code I used:
Dim lAttachments As New List(Of System.Net.Mail.Attachment)
For Each lFile As Telerik.Web.UI.UploadedFile In RadAsyncUploadAllegati.UploadedFiles
Dim attachment As New System.Net.Mail.Attachment(lFile.InputStream, lFile.FileName)
lAttachments.Add(attachment)
Next
Dim lblnErrori As Boolean
Try
Dim lstrRisultato As String
lstrRisultato = DotNetNuke.Services.Mail.Mail.SendMail(lstrHostEMail, lstrDestinatarioHelpDesk, String.Empty, String.Empty, txtEMail.Text.Trim, Services.Mail.MailPriority.Normal, lstrOggetto, Services.Mail.MailFormat.Html, System.Text.Encoding.UTF8, lstrBody, lAttachments, lstrSMTPServer, "", "", "", False)
Catch ex As Exception
lblnErrori = True
End Try
If Not lblnErrori Then
pnlRichiesta.Visible = False
pnlConferma.Visible = True
Else
lblErrori.Text = "Impossibile inviare il messaggio!"
End If
lAttachments.Clear()
For Each lFile As Telerik.Web.UI.UploadedFile In RadAsyncUploadAllegati.UploadedFiles
Dim lstrNomeFileTemporaneo As String
lstrNomeFileTemporaneo = DirectCast(lFile.InputStream, System.IO.FileStream).Name
Try
lFile.InputStream.Close()
lFile.InputStream.Dispose()
Catch ex As Exception
End Try
Try
System.IO.File.Delete(lstrNomeFileTemporaneo) 'THIS LINE PRODUCES ERROR
Catch ex As Exception
End Try
Next
Thanks