我想这可以作为一个修辞问题。我发布它是因为没有单一的答案处理我的问题,我不得不拼凑几个来源的答案。我认为合并可能会有所帮助。
使用Visual Basic,我需要允许我们的Web应用程序用户向我们发送文件和图像文件,以支持在标准用户界面上输入的其他信息。
我们的管理层不希望任何文件上传到我们的网络服务器。他们希望所有内容都通过电子邮件,以限制对服务器的访问,因为我们已经为电子邮件病毒和安全筛选付费。
我希望用户能够发送多个文件。
由于我们想要解释他们发送给我们的内容,因此该信息在富文本编辑器中捕获并用作邮件正文。
我们希望以最基本的形式保留它 - 没有javascript,jquery,没有AJAX,LINQ或其他Microsoft增强功能。
答案 0 :(得分:0)
所以,这就是我们所做的。
ASP编码 -
<form runat="server" id="form1">
<div class="row">
<div class="col-sm-6"><asp:Label runat="server" ID="lblWelcomeMssg" /></div>
</div>
<div class="row">
<asp:FileUpload ID="selectedFiles" AllowMultiple="true" runat="server" /><br />
<div class="col-sm-3"><asp:Label runat="server" ID="lblStatus" Text="" ForeColor="Red" /></div>
</div>
<div class="row">
<div class="col-sm-1"><br /><br /></div>
</div>
<div class="row">
<div class="col-sm-10"><asp:TextBox runat="server" ID="rteBody" TextMode="MultiLine" /></div>
</div>
<div class="row">
<div class="col-sm-1"><br /></div>
</div>
<div class="row">
<div class="col-sm-1"><asp:Button runat="server" ID="btnSend" Text="Send" /></div>
<div class="col-sm-2"><asp:Button runat="server" ID="btnClear" Text="Clear" /></div>
</div>
然后所有动作都在选择多个文件后发生,当&#34;发送&#34;单击按钮。注意:ContactInfo只是我为便于处理用户信息而创建的vb类。
Codebehind -
Imports System.Net
Imports System.Net.Mail
Imports System.Windows.Forms
Imports System.IO
Imports System.Web
Public Class SendUsTheFiles
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
If Session("AUTHENTICATED_USER") Then
lblWelcomeMssg.Text = "{Welcome... and instructions....}<br /><br />"
Else
Response.Redirect("SignIn.aspx")
End If
End If
End Sub
Protected Sub btn_Send_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSend.Click
Dim fileSendMail As New MailMessage
Dim usrID As String = Session.Item("USER_ID")
Dim IndEmailInfo As New ContactInfo
IndEmailInfo = ContactGet(usrID)
' ContactGet is a global function that retrieves user name and email information from our SQL database
Dim FromAdd As New MailAddress(IndEmailInfo.emailAddr, IndEmailInfo.Name)
Dim oServer As New SmtpClient
Dim txtHtmlBody As String = rteBody.Text
Dim fileCount As Integer = 0
Dim ToAdd As New MailAddress("officeFolk@ourorg.org", "Customer Services")
Dim ccAdd As New MailAddress("admin@ourorg.org", "Polo Holeset")
Dim objMail As New MailMessage(FromAdd, ToAdd)
objMail.CC.Add(ccAdd)
If selectedFiles.HasFiles = True Then
For Each uploadedFile As HttpPostedFile In selectedFiles.PostedFiles
Try
Dim strFileName As String = System.IO.Path.GetFileName(uploadedFile.FileName)
Dim attachment As New Attachment(uploadedFile.InputStream, strFileName)
objMail.Attachments.Add(attachment)
fileCount = fileCount + 1
Catch
End Try
Next
End If
oServer.Host = "mail.ourorg.org"
oServer.UseDefaultCredentials = True
objMail.Subject = "File submission"
objMail.IsBodyHtml = True
objMail.Body = txtHtmlBody
Try
oServer.Send(objMail)
lblStatus.Text = fileCount.ToString & " files successfully sent."
rteBody.Text = String.Empty
Catch ex As Exception
End Try
End Sub
...............