模拟邮箱

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
     <script language="javascript" type="text/javascript">
// <![CDATA[

         function Button1_onclick() {
//             var str = "<input type='file' name='files'/><br/>";
             var mydiv = document.getElementById("divFiles");
             //            mydiv.insertAdjacentHTML("beforeEnd", str);
             var inp = document.createElement("input");
             inp.type = "file";
             inp.name = "files";
             mydiv.appendChild(inp);

         }

// ]]>
     </script>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            text-align: right;
            width: 62px;
        }
        .style3
        {
            width: 62px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <table class="style1">
            <tr>
                <td class="style2">
                    发信人:</td>
                <td>
                    <asp:DropDownList ID="DropDownList1" runat="server"
                        DataSourceID="SqlDataSource1" DataTextField="fajianren"
                        DataValueField="fajianren">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                        ConnectionString="<%$ ConnectionStrings:邮件ConnectionString %>"
                        SelectCommand="SELECT [fajianren] FROM [Table_1]"></asp:SqlDataSource>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    收信人:</td>
                <td>
                    <asp:DropDownList ID="DropDownList2" runat="server"
                        DataSourceID="SqlDataSource2" DataTextField="shoujianren"
                        DataValueField="shoujianren">
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSource2" runat="server"
                        ConnectionString="<%$ ConnectionStrings:邮件ConnectionString2 %>"
                        SelectCommand="SELECT [shoujianren] FROM [Table_2]"></asp:SqlDataSource>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    主题:</td>
                <td>
                    <asp:TextBox ID="txtzhuti" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    &nbsp;</td>
                <td>
                    <input id="Button1" type="button" value="添加附件" onclick="return Button1_onclick()" />
                    <asp:Button ID="Button4" runat="server" Text="上传" onclick="Button4_Click" />
                </td>
            </tr>
            <tr>
                <td class="style2">
                    &nbsp;</td>
                <td>
                    <div id="divFiles">
                    </div>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    正文:</td>
                <td>
                    <asp:TextBox ID="txtneirong" runat="server" Height="197px" Width="441px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="style3">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style3">
                    &nbsp;</td>
                <td>
                    <asp:Button ID="Button3" runat="server" Text="发送" onclick="Button3_Click" />
                </td>
            </tr>
            <tr>
                <td class="style3">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style3">
                    &nbsp;</td>
                <td>
                    &nbsp;</td>
            </tr>
        </table>
   
    </div>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < this.Request.Files.Count; i++)
        {
            HttpPostedFile file = this.Request.Files[i];
            string filename = System.IO.Path.GetFileName(file.FileName);
            file.SaveAs(Server.MapPath("~/") + filename);
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        if (!Directory.Exists(Server.MapPath("userimage") + "/" + DropDownList1.Text + "-to-" + DropDownList2.Text))    //判断是否文件存在,存在就不执行创建命令了
        {
            Directory.CreateDirectory(Server.MapPath("userimage") + "/" + DropDownList1.Text + "-to-" + DropDownList2.Text);
        }

        for (int i = 0; i < Request.Files.Count; i++)       //进行所有用用动态添加的fileupload控件集合的遍历,分别进行存储
        {

            HttpPostedFile file = Request.Files[i];
            string filename = System.DateTime.Now.Ticks.ToString() + System.IO.Path.GetFileName(file.FileName);
            file.SaveAs(Server.MapPath("userimage") + "/" + DropDownList1.Text + "-to-" + DropDownList2.Text + "/" + filename);
        }

 

    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值