Danish Habib

Danish Habib

  • NA
  • 694
  • 242.8k

Sending file as attachment and saving into the database Erro

Oct 20 2015 8:43 AM
I have a application in which i give the user that he can upload a file when he click the button this files is gone to some email address with attachment and also this file save into the db below is my code please any one can help out i am highliting the line which produces an error if i omit this line the functions runs well and attachment come blank.
Protected Sub ContactUsclick()
Try
If ctrlGoogleReCaptcha.Validate Then
Dim ID = System.Guid.NewGuid
Dim FullNameText = Trim(FullName.Value)
Dim CompanyNameText = Trim(CompanyName.Value)
Dim EmailText = Trim(Email.Value)
Dim PhoneText = Phone.Value
Dim SerialNumberText = SerialNumber.Value
Dim ProductLocationAddress = ProductLocation.Value
Dim CommentText = Trim(Comment.Value)
DataAccessLayer.DataAccess.InsertServiceRequest(ID, FullNameText,
CompanyNameText, EmailText, _
PhoneText,
SerialNumberText, ProductLocationAddress, CommentText)
Dim AttachmentList As New List(Of Attachment)
For Each UploadedFile As HttpPostedFile In FileUpload.PostedFiles
Dim ServiceQueueUniqueIdentifier = System.Guid.NewGuid
Dim strFileName As String =
System.IO.Path.GetFileName(UploadedFile.FileName)
Dim attachment As New Attachment(UploadedFile.InputStream,
strFileName)
AttachmentList.Add(attachment)
Dim fs As Stream = UploadedFile.InputStream
Dim br As New BinaryReader(fs)
‘This line below is the issue. If I comment out this line I get the
emails fine with the attachments. When I leave this line in here my emails come with
blank attachments. Not sure why this line is messing up
DataAccessLayer.DataAccess.InsertServiceRequestAttachments(ServiceQueueUniqueIdentifier,
ID, UploadedFile.FileName, UploadedFile.ContentType, br.ReadBytes(fs.Length))
Next
Dim body As String =
BusinessLogic.Utilities.MailingFunctions.FormatServiceRequestToXML(FullNameText,
CompanyNameText, EmailText, PhoneText, _
SerialNumberText, ProductLocationAddress, CommentText, AttachmentList.Count)
BusinessLogic.Utilities.MailingFunctions.SendSMTPContactRequest("""Phiston Feedback
Mailer""" & "<" & ConfigurationManager.AppSettings("ContactUSFromEmailAddress") & ">", _
"[email protected]", "Service
Request Received", body, AttachmentList, Nothing)
'BusinessLogic.Utilities.MailingFunctions.SendSMTPContactRequest("""Phiston Feedback
Mailer""" & "<" & ConfigurationManager.AppSettings("ContactUSFromEmailAddress") & ">", _
'
ConfigurationManager.AppSettings("ServiceContactToEmailAddress"), "Service Request
Received", body, AttachmentList, Nothing)
Response.Redirect("contactthanks.aspx")
Else
ErrorLbl.Visible = True
End If
Catch ex As Exception
Throw
End Try
End Sub
Please assists me in that regards Thanks for helping me out

Answers (2)