您现在的位置: PQ秀秀网 >> 网络编程 >> ASP.NET编程 >> 正文 用户登录 新用户注册
用asp.net编写的上传程序
作者:佚名    教程来源:不详    点击数:加载中...    更新时间:2007-12-29 字体:[ ]
添加到收藏: 添加到百度收藏  收藏到QQ书签  添加到雅虎收藏  添加到新浪ViVi  添加到天极网摘  添加到和讯网摘

<%--
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>
<br>
<br>
<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>
<br>
<br>
<br>
<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>

教程录入:andy    责任编辑:andy 
  网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)