📄 fileupload.aspx
字号:
<%@ Import Namespace="System.IO" %>
<%@ page Language="C#" debug="true" %>
<html>
<head>
<title>FileUpload ,By Gordan Cao-http://www.caogjwj.com </title>
<script language="C#" runat="server">
//This method is called when the 'upload' button ID pressed
public void UploadFile(object sender , EventArgs E)
{
//check if the fileposted is not null
if(myFile.PostedFile!=null)
{
//some string manipulations to extract the filename from the full file path
string nam = myFile.PostedFile.FileName ;
int i= nam.LastIndexOf("\\") ;
string newnm =nam.Substring(i) ;
//save the file to the destination path on your server
//change this path as per your needs (remember the path you specify should exist and have 'write' access)
//Note: I have used "c:\\" etc the "\\" is because I have to give a escape character
//in a string
myFile.PostedFile.SaveAs("d:\\inetpub\\wwwroot\\upload\\"+newnm) ;
//Get the various properties of the Uploaded file
fname.Text=myFile.PostedFile.FileName;
fenc.Text=myFile.PostedFile.ContentType ;
fsize.Text=myFile.PostedFile.ContentLength.ToString();
}
}
</script>
</head>
<body>
<center>
<h3> File Upload Demo Program, by Gordan Cao</h3>
<form id="uploderform" method="post" action="FileUpload.aspx" enctype="multipart/form-data" runat="server" >
<table border="1" cellspacing="2" cellpadding="2" >
<tr> <td><h5>Select the File to upload</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="2">
<tr><td><b>File Details</b></td>
<td> </td>
</tr>
<tr>
<td>File Name :</td>
<td><asp:label id="fname" text="" runat="server" /></td></tr>
<tr>
<td>File Encoding :</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>
<br>
<br>
<br>
<h5>This example has been downloaded from <a href="http://www.caogjwj.com">http://www.caogjwj.com</a> .
You can find more such examples here. If you have any questions, comments or suggestion feel free to contact the author
Gordan Cao at <a href="mailto:caogjwj@sina.com">caogjwj@sina.com</a>.</h5>
</center>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -