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

Danish HabibPosted Oct 20, 2015, 2:42 PM
I want to take the uploaded Files an do 2 things
1) Save files to Database
2) Email Files
The problem is I cant do both and let me explain why
This one line of code is causing a problem
DataAccessLayer.DataAccess.InsertServiceRequestAttachments(ServiceQueueUniqueIdentifier, ID, UploadedFile.FileName, UploadedFile.ContentType, br.ReadBytes(fs.Length))
That is the line that inserts the files into the database
that part works..
it inserts the data into the database no problem.. BUT
when that line is there when I get the emails the attachments are blank
If I take that line out... I get the email with the attachments no problem
make sense?
If I omit that line I get the attachments fine in the email
If i add the line. It saves to Database no problem but email has issues
So not sure why but something on that line is causing my email attachments to get cleared
Sujeet SumanPosted Oct 20, 2015, 12:13 PM