fileupload应用 上传数据自己选择收件人选择上传的附件点发送后会创建一个文件夹存入你上传的附件
2012-10-02 22:31
423 查看
aspx中
<%@ Page Xlanguage="C#" AutoEventWireup="true" CodeFile="网易邮箱.aspx.cs" Inherits="网易邮箱" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<table runat="server">
<tr><td></td><td><asp:Label ID="Label1" runat="server" Text="网易邮箱"></asp:Label></td></tr>
<tr><td>发件人:</td><td>
<asp:DropDownList ID="DropDownList2" runat="server" Height="20px" Width="135px">
<asp:ListItem>李逸</asp:ListItem>
<asp:ListItem>刘洪</asp:ListItem>
<asp:ListItem>张展</asp:ListItem>
</asp:DropDownList>
</td></tr>
<tr><td>收件人:</td><td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="44px" Width="135px">
<asp:ListItem>王五</asp:ListItem>
<asp:ListItem>张三</asp:ListItem>
<asp:ListItem>河汉</asp:ListItem>
</asp:DropDownList>
</td></tr>
<tr><td>
<asp:FileUpload ID="FileUpload1" runat="server" /></td><td>
<asp:Label ID="Label2" runat="server"></asp:Label>
</td></tr>
<tr><td></td><td>
<asp:Button ID="Button2" runat="server" Text="发送" Xonclick="Button2_Click" />
<asp:Label ID="Label3" runat="server"></asp:Label>
</td></tr>
</table>
</div>
</form>
</body>
</html>
cs中
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 网易邮箱 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
Label2.Text += FileUpload1.PostedFile.FileName + " ";
HttpFileCollection hf = Request.Files;
for (int i = 0; i < hf.Count; i++)
{
HttpPostedFile hp = hf[i];
if (hp.ContentLength > 0)
{
if (!Directory.Exists(@"E:\" + DropDownList2.Text)) //判断文件夹是否存在
{
Directory.CreateDirectory(@"E:\" + DropDownList2.Text);//不存在则创建文件夹
}
int a = hp.ContentLength;
Label3.Text = a.ToString();
//File.Create(@"E:\" + DropDownList2.Text, hp.ContentLength);
string filename = hp.FileName;
string path = @"E:\" + DropDownList2.Text;
hp.SaveAs(path + @"\" +Path.GetFileName( filename));
}
}
}
}
<%@ Page Xlanguage="C#" AutoEventWireup="true" CodeFile="网易邮箱.aspx.cs" Inherits="网易邮箱" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<table runat="server">
<tr><td></td><td><asp:Label ID="Label1" runat="server" Text="网易邮箱"></asp:Label></td></tr>
<tr><td>发件人:</td><td>
<asp:DropDownList ID="DropDownList2" runat="server" Height="20px" Width="135px">
<asp:ListItem>李逸</asp:ListItem>
<asp:ListItem>刘洪</asp:ListItem>
<asp:ListItem>张展</asp:ListItem>
</asp:DropDownList>
</td></tr>
<tr><td>收件人:</td><td>
<asp:DropDownList ID="DropDownList1" runat="server" Height="44px" Width="135px">
<asp:ListItem>王五</asp:ListItem>
<asp:ListItem>张三</asp:ListItem>
<asp:ListItem>河汉</asp:ListItem>
</asp:DropDownList>
</td></tr>
<tr><td>
<asp:FileUpload ID="FileUpload1" runat="server" /></td><td>
<asp:Label ID="Label2" runat="server"></asp:Label>
</td></tr>
<tr><td></td><td>
<asp:Button ID="Button2" runat="server" Text="发送" Xonclick="Button2_Click" />
<asp:Label ID="Label3" runat="server"></asp:Label>
</td></tr>
</table>
</div>
</form>
</body>
</html>
cs中
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 网易邮箱 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
Label2.Text += FileUpload1.PostedFile.FileName + " ";
HttpFileCollection hf = Request.Files;
for (int i = 0; i < hf.Count; i++)
{
HttpPostedFile hp = hf[i];
if (hp.ContentLength > 0)
{
if (!Directory.Exists(@"E:\" + DropDownList2.Text)) //判断文件夹是否存在
{
Directory.CreateDirectory(@"E:\" + DropDownList2.Text);//不存在则创建文件夹
}
int a = hp.ContentLength;
Label3.Text = a.ToString();
//File.Create(@"E:\" + DropDownList2.Text, hp.ContentLength);
string filename = hp.FileName;
string path = @"E:\" + DropDownList2.Text;
hp.SaveAs(path + @"\" +Path.GetFileName( filename));
}
}
}
}
相关文章推荐
- fileupload应用 上传数据自己选择收件人选择上传的附件点发送后会创建一个文件夹存入你上传的附件
- fileupload应用 上传数据自己选择收件人选择上传的附件点发送后会创建一个文件夹存入你上传的附件
- 一个简单地应用--从客户端向服务器发送数据.post,get.httpclientget,httpclinetpost,文件上传.
- 创建自己的Application,以在整个应用中分享数据(程序启动时会默认创建一个Application)
- 自己创建一个sd下面的文件夹作为硬盘缓存的路径
- 提交订单系统自动发送邮件到收件人邮箱优化(邮件正文内容为当天数据,附件内容为当月数据)
- oracle授权另外一个用户访问自己创建的数据对象
- 无废话Android之listview入门,自定义的数据适配器、采用layoutInflater打气筒创建一个view对象、常用数据适配器ArrayAdapter、SimpleAdapter、使用ContentProvider(内容提供者)共享数据、短信的备份、插入一条记录到系统短信应用(3)
- 提交订单系统自动发送邮件到收件人邮箱优化(邮件正文内容为当天数据,附件内容为当月数据)
- 【Xamarin开发 Android 系列 12】 创建一个Json读取数据应用-添加定位服务
- 创建一个类似发送短信时的软键盘,是需要自己实现还是改变软键盘类型?
- 提交订单系统自动发送邮件到收件人邮箱优化(邮件正文内容为当天数据,附件内容为当月数据)
- 【Xamarin开发 Android 系列 11】 创建一个Json读取数据应用-添加摄像头集成
- xcode 下创建文件夹,并在文件夹下创建文件时没有弹出选择界面,直接生成了一个 file
- {网络编程}和{多线程}应用:基于UDP协议【实现多发送方发送数据到同一个接收者】--练习
- 将标题内容及附件同时发送请看看下面代码上传数据为什么有空值和数据
- 提交订单系统自动发送邮件到收件人邮箱优化(邮件正文内容为当天数据,附件内容为当月数据)
- [原]as3 flash web 应用 (8)图片批量上传之 向服务器发送和获取额外数据
- 11-28 自己写一个数据集DataSet---ds,向其中添加一个数据表DataTable ---dt,并创建该表的列和行。然后将本本表作为数据源绑定到GradView中。
- 提交订单系统自动发送邮件到收件人邮箱优化(邮件正文内容为当天数据,附件内容为当月数据)