asp.net多文件上传

[ 1801 查看 / 5 回复 ]

<%@ 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><aspabel ID="fname" Text="" runat="server" /></td>         </tr>         <tr>             <td>文件类型</td>             <td><aspabel ID="fenc" runat="server" /></td>         </tr>         <tr>             <td>文件大小(in bytes)</td>             <td><aspabel ID="fsize" runat="server" /></td>         </tr>     </table> </div> </body> </html>
分享 转发
TOP

TOP

TOP

TOP

aa
a.jpg ()

jpg (2008-8-21 16:39:02)

a.jpg

TOP

快快顶















中通快递
TOP