I’m trying to add an attachment to my email from a browse button in c#
Here is my code:
string fileName = Path.Combine(Path.GetTempPath(),FileUploadControl.FileName);
using (FileStream fs = File.Open(fileName, FileMode.Create, FileAccess.Write, FileShare.Read))
{
byte[] buffer = new byte[1024];
int bytesRead; while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0)
{
fs.Write(buffer, 0, bytesRead);
}
}
Attachment attachment = new Attachment(fileName);
msg.Attachments.Add(attachment);
$exception {“Stream does not support reading.”} System.Exception {System.NotSupportedException}
what am i doing wrong?
You got close. You meant to read from the file input stream but didn’t: