<%-- 
upload.aspx 
这是一个上传文件,从中我们可以看出asp.net的优势,以前需要控件才能完成的程序,现在只需要几行代码就可以轻松完成。 
--%> 
<%@ import namespace="system.io" %> 
<%@ page language="c#" debug="true" codepage="936"%> 
<html> 
<head> 
<title>文件上传,aspcool.com </title> 
<script language="c#" runat="server"> 
public void uploadfile(object sender , eventargs e) 
{ 
if(myfile.postedfile!=null) 
{ 
//定义一些变量 
string nam = myfile.postedfile.filename ; 
int i= nam.lastindexof("//") ; 
string newnm =nam.substring(i) ; 
//改变下面的“c://"到你想要保存的地址。 
myfile.postedfile.saveas("c://"+newnm) ; 
//取得上传文件的各种属性。 
fname.text=myfile.postedfile.filename; 
fenc.text=myfile.postedfile.contenttype ; 
fsize.text=myfile.postedfile.contentlength.tostring(); 
} 
} 
</script> 
</head> 
<body> 
<center> 
<h3> 文件上传演示,飞鹰制作 </h3> 
<form id="uploderform" method="post" action="upload.aspx" enctype="multipart/form-data" runat="server" > 
<table border="1" cellspacing="0" cellpadding="0" > 
<tr> <td><h5>选择文件</h5></td</tr> 
<tr><td> 
<input type="file" id="myfile" runat="server" > 
</td></tr> 
<tr><td> 
<input type="button" value="upload" onserverclick="uploadfile" runat="server" > 
</td></tr> 
</table> 
</form> 
 
 
<table border="1" cellspacing="0"> 
<tr><td><b>文件资料</b></td> 
<td> </td> 
</tr> 
<tr> 
<td>文件名称 :</td> 
<td><asp:label id="fname" text="" runat="server" /></td></tr> 
<tr> 
<td>文件类型 :</td> 
<td><asp:label id="fenc" runat="server" /></td></tr> 
<tr> 
<td>文件大小 :(in bytes)</td> 
<td><asp:label id="fsize" runat="server" /></td></tr> 
</table> 
 
 
 
<h5>你可以从 <a href="http://www.aspcool.com/download">http://www.aspcool.com/download</a> 下载该程序.我们将给您提供更多的其它程序。如果有什么意见请到我的<a href="http://www.chaxiu.com/club/right.php?boardid=7&page=1">asp论坛</a>来讨论。</h5> 
</center> 
</body> 
</html>  
新闻热点
疑难解答
图片精选