shelbyinfotech
asked on
Adding an attachment to email vb.net from upload httppostedfile.
I am currently taking the uploaded file and saving it to disk. Then, I attach it to an email. This works however, sometimes, (inconsistent) it claims the file is in use by another process and won't save it to disk. I had the bright idea that I could attach the filestream directly to the mailmessage.attachment.add . I have not been able to get this to work. I actually succeeded but the file that was attached had nothing in it. It had the right name though. The command I tried was:
mailmessage.attachments.ad d(new attachment(uploadname.post edfile.inp utstream, uploadname.postedfile.file name))
Any ideas? I've found lots of stuff about how to save the file to disk and then attach that but I'm trying to get away from that.
mailmessage.attachments.ad
Any ideas? I've found lots of stuff about how to save the file to disk and then attach that but I'm trying to get away from that.
ASKER
Here you know you are writing a csv and are supplying the mime type. I don't know this. Can be a pdf, a word doc, anything the user uploads. Is not the postedfile.inputstream already a memory stream? vb.net would also be helpful.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
the code I provided in https://www.experts-exchange.com/questions/29008033/Adding-an-attachment-to-email-vb-net-from-upload-httppostedfile.html?notificationFollowed=185654205&anchorAnswerId=42043308#a42043308 shows similar code to the proposed solution.
Specifically taking a memory stream and creating an attachment from it. How the information got to the memory stream is the only difference.
Specifically taking a memory stream and creating an attachment from it. How the information got to the memory stream is the only difference.
ASKER
Well, the piece that was missing was the part I was asking about. I too had found the post about the memory stream. I don't care. If it's that big of a deal to you, you can claim the solution. I needed to do that other part and I did figure that out. If you want the points for googling it and copying and pasting something that referred to what I was talking about, I'm not going to stand in your way. Let the moderators sort it out.
Open in new window