You want to make a simple WebForm that allows your students
to submit a simple e-mail message with a file attachment to submit a term paper.
Since the attachment is being sent via e-mail to a recipient, there is no need
for you to store the attachment on the file system.
To achieve this, I would simply make a WebForm with the
Figure 1 - WebForm for message
<img width=355 height=355 src="/ArticleFiles/913/image001.gif">
The listing does not include any error checking and also
assumes that the student will be uploading a MS Word document. I kept this
short and sweet for demonstration purposes, but it is functional.
Listing 2 - Attaching a file with contentstream
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Dim msg As New System.Net.Mail.MailMessage()
Dim smtp As New System.Net.Mail.SmtpClient("127.0.0.1")
Dim fromadx As New System.Net.Mail.MailAddress("firstname.lastname@example.org", "Term
Dim toadx As New System.Net.Mail.MailAddress("email@example.com",
msg.From = fromadx
msg.Subject = txtSubject.Text
msg.Body = txtBody.Text
If FileUpload1.HasFile = True Then
System.Net.Mail.Attachment(FileUpload1.PostedFile.InputStream, "Final Term
Another good use for the contentstream attachment is when
the file exists in a byte() array. The byte() data can be put into a System.IO.MemoryStream which is then readable by the
I have used that technique with SQL database image fields.
Listing 3 - MemoryStream example
'Assumes you have a datatable with SQL image data in it.
Dim ms as new System.IO.MemoryStream(Table1.rows(0).item("ImageFieldName"))
The MemoryStream now contains the
contents of the image data from Table1. It can be read by the System.Net.Mail.Attachment object.