Asp.net| Program | upload
<%--
Upload.aspx
This is an upload file, from which we can see the advantages of ASP.net, the previous need for control to complete the program, now only need a few lines of code can be easily completed.
--%>
<%@ Import namespace= "System.IO"%>
<%@ page language= "C #" debug= "true" codepage= "936"%>
<title> file Upload, aspcool.com </title>
<script language= "C #" runat= "Server" >
public void UploadFile (object sender, EventArgs E)
{
if (myfile.postedfile!=null)
{
Define some variables
String nam = MyFile.PostedFile.FileName;
int i= Nam. LastIndexOf ("\");
String Newnm =nam. Substring (i);
Change the "c:\\" below to the address you want to save.
MyFile.PostedFile.SaveAs ("c:\\" +newnm);
Gets the various attributes of the uploaded file.
FName. Text=myfile.postedfile.filename;
Fenc. Text=myfile.postedfile.contenttype;
Fsize. Text=myfile.postedfile.contentlength.tostring ();
}
}
</script>
<body>
<center>
<form id= "Uploderform" method= "post" action= "upload.aspx" enctype= "Multipart/form-data" runat= "Server" >
<table border= "1" cellspacing= "0" cellpadding= "0" >
<tr> <td><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> Documents </b></td>
<td> </td>
</tr>
<tr>
<td> file name:</td>
<td><asp:label id= "fname" text= "" runat= "Server"/></td></tr>
<tr>
<td> File Type:</td>
<td><asp:label id= "Fenc" runat= "Server"/></td></tr>
<tr>
<td> file Size:(in bytes) </td>
<td><asp:label id= "fsize" runat= "Server"/></td></tr>
</table>
</center>
</body>