其他分享
首页 > 其他分享> > Upload Images and Send Them as Email Attachments

Upload Images and Send Them as Email Attachments

作者:互联网

原文链接:http://www.cnblogs.com/HenryLiang/archive/2006/06/15/Upload_Image_And_Send_With_Email.html

今天要写一个小web application,允许用户上传最多到3张图片(网页上有3个文件上传框),然后将图片压缩之后添加到email中作为附件,最后用服务器上的smtp server发送email。听起来很简单,但是当中却包含了一个潜在的usability问题。
这个问题发生在,当用户没有使用第一个上传框而是用第二个或是第三个上传框,当我在Iterate httpUploadedFiles时,就会导致第一个上传文件为空。这样当我再将这个空的图片作为附件添加到email的时候,就会导致错误。当然,按照一般的使用规律,用户当然会先选择第一个上传框,然后第二个……但是不能够排除某些时候的特定情况,这也是程序强健性的表现。
这个问题有两种解决方法,
1. 修改页面结构。一开始只显示一个上传框,如果有必要,允许用户“添加下一张图片”,就像hotmail那样。
2. 用程序来检测哪个上传框中真正上传了文件。
我采用了第二个办法,下面是代码:

None.gifDim hpc As HttpFileCollection = HttpContext.Current.Request.Files
None.gifDim ht2 As New Hashtable
None.gifIf Not hpc Is Nothing Then
None.gif    Dim i As Integer = 0
None.gif    Dim c As Integer = 0
None.gif    While c < hpc.Count
None.gif        Dim file As System.Web.HttpPostedFile = hpc(c)
None.gif        If (Not file Is Nothing) And (file.ContentLength > 0) Then
None.gif            Dim str As String = SaveImage(file)
None.gif            ht2.Add("Image" & i.ToString(), str)
None.gif            i = i + 1
None.gif        End If
None.gif        c = c + 1
None.gif    End While
None.gifEnd If

转载于:https://www.cnblogs.com/HenryLiang/archive/2006/06/15/Upload_Image_And_Send_With_Email.html

标签:Dim,Them,Attachments,Upload,Send,email,file,上传,Email
来源: https://blog.csdn.net/weixin_30908103/article/details/98049126