快速搜索
[登录]
[注册]
搜索
OPK网站首页
标签
帮助
OPK 偶匹克论坛
»
站务事务管理处
»
站务管理中心
»
asp.net多文件上传
asp.net多文件上传
[
1801
查看 /
5
回复 ]
返回列表
发送短消息
UID
1
精华
13
查看公共资料
搜索帖子
admin
admin
组别
管理员
帖子
113
积分
191
性别
注册时间
2008-07-31
admin
2008-08-18 15:23
|
只看楼主
1
#
字体大小:
t
T
<%@ Import Namespace="System.IO" %> <%@ page Language="C#" debug="true" %> <html> <head> <title>文件上传的实例</title> <script language="C#" runat="server"> //This method is called when the "upload" button id pressed public void UploadFile(object sender , EventArgs E) { HttpFileCollection myFile = HttpContext.Current.Request.Files; for(int i=0; i<myFile.Count; i++) { HttpPostedFile postedFile = myFile
; if(postedFile.ContentLength != 0) { string fileName = Path.GetFileName(postedFile.FileName); DateTime now = DateTime.Now; string nowtime=now.Year.ToString()+now.Month.ToString()+now.Day.ToString()+now.Hour.ToString()+now.Minute.ToString()+now.Second.ToString(); //获得文件名扩展 string fileExtension = System.IO.Path.GetExtension(fileName); //保存文件到你所要的目录,这里是IIS根目录下的upfiles目录.你可以改变. //注意: 我这里用Server.MapPath()取当前文件的绝对目录.在asp.net里"\"必须用"\\"代替 // postedFile.SaveAs(Server.MapPath("\\upfiles\\"+nowtime+fileName)); postedFile.SaveAs(Request.MapPath("upFiles/") +nowtime+fileName); //得到这个文件的相关属性:文件名,文件类型,文件大小 fname.Text=postedFile.FileName; fenc.Text=postedFile.ContentType+"<br>"+fileExtension; fsize.Text=postedFile.ContentLength.ToString()+"<br>"+nowtime.ToString(); } } } </script> </head> <body> <h3 align="center">文件上传的实例 </h3> <div align="center"> <table border="1" cellspacing="2" cellpadding="2"> <form id="uploderform" method="post" action="FileUpload.aspx" enctype="multipart/form-data" runat="server"> <tr> <td><h5 align="center">选择要上传的文件:</h5></td> </tr> <tr> <td><input type="file" id="myFile" name="myFile"></td> </tr> <tr> <td><input type="file" id="File1" name="myFile"></td> </tr> <tr> <td><input type="file" id="File2" name="myFile"></td> </tr> <tr> <td><input type="button" value="上 传" runat="server" id="Button1" name="Button1"></td> </tr> </form> </table> </div> <br> <br> <div align="center"> <table border="1" cellspacing="2"> <tr> <td><b>文件资料</b></td> <td> </td> </tr> <tr> <td>文件名</td> <td><asp
abel ID="fname" Text="" runat="server" /></td> </tr> <tr> <td>文件类型</td> <td><asp
abel ID="fenc" runat="server" /></td> </tr> <tr> <td>文件大小(in bytes)</td> <td><asp
abel ID="fsize" runat="server" /></td> </tr> </table> </div> </body> </html>
分享
转发
TOP
发送短消息
UID
1
精华
13
查看公共资料
搜索帖子
admin
admin
组别
管理员
帖子
113
积分
191
性别
注册时间
2008-07-31
admin
2008-08-18 15:31
|
只看楼主
2
#
字体大小:
t
T
TOP
发送短消息
UID
1
精华
13
查看公共资料
搜索帖子
admin
admin
组别
管理员
帖子
113
积分
191
性别
注册时间
2008-07-31
admin
2008-08-18 15:31
|
只看楼主
3
#
字体大小:
t
T
2.jpg
(121.52 K)
2008-8-18 15:31:22
TOP
发送短消息
UID
1
精华
13
查看公共资料
搜索帖子
admin
admin
组别
管理员
帖子
113
积分
191
性别
注册时间
2008-07-31
admin
2008-08-18 15:33
|
只看楼主
4
#
字体大小:
t
T
TOP
发送短消息
UID
1
精华
13
查看公共资料
搜索帖子
admin
admin
组别
管理员
帖子
113
积分
191
性别
注册时间
2008-07-31
admin
2008-08-21 16:33
|
只看楼主
5
#
字体大小:
t
T
aa
a.jpg
()
jpg
(2008-8-21 16:39:02)
TOP
发送短消息
UID
293
精华
0
查看公共资料
搜索帖子
piaqf655
组别
注册会员
帖子
57
积分
58
性别
注册时间
2009-02-25
piaqf655
2009-04-01 09:52
|
只看该用户
6
#
字体大小:
t
T
快快顶
中通快递
TOP
返回列表
上一主题
|
下一主题
发新主题
帖子标题
作者
版块
我的资料