用 Asp.net 编写的上传程序

来源: 作者: 2006-04-15 出处:pcdog.com


  <%@ 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=7page=1">ASP论坛</a>来讨论。</h5>

</center>

</body>

</html>
更多内容请看PCdog.com--ASP.NET应用篇专题
上一篇:ASP.NET应用程序设计的10大技巧
下一篇:ASP.NET中利用存储过程实现模糊查询