M
MichaelLee
Unregistered / Unconfirmed
GUEST, unregistred user!
//单个文件上传代码,测试通过
<Script Language="C#" Runat="Server">
public void Page_Load(Object src,EventArgs e)
{
//设置HtmlInputFile控件的属性
UploadFile.MaxLength = 30;
UploadFile.Size = 20;
}
public voiddo
Upload(Object src,EventArgs e)
{
HttpPostedFile hpf = UploadFile.PostedFile;
FileName.Text = hpf.FileName;
FileSize.Text = hpf.ContentLength.ToString();
//取得文件名(不含路径)
char[] de = {'//'};
string[] AFilename = hpf.FileName.Split(de);
string strFilename = AFilename[AFilename.Length-1];
rname.Text = strFilename;
hpf.SaveAs(Server.MapPath(".")+"//"+strFilename);
}
</script>
<html>
<head>
<title>上传单个文件</title>
</head>
<body>
<form Enctype="multipart/form-data" runat="server">
<b>上传单个文件示例</b>
<hr>
请选择文件上传:<input type="file" id="UploadFile" runat="server"><br>
<input type="submit" value="上传" OnServerClick="DoUpload" runat="server">
<hr>
上传文件名:<asp:Label id="FileName" Text="尚未上传" runat="server" /><br>
上传文件大小:<asp:Label id="FileSize" Text="尚未上传" runat="server" /><br>
真实文件名:<asp:Label id="rname" Text="尚未上传" runat="server" />
</form>
</body>
</html>
<Script Language="C#" Runat="Server">
public void Page_Load(Object src,EventArgs e)
{
//设置HtmlInputFile控件的属性
UploadFile.MaxLength = 30;
UploadFile.Size = 20;
}
public voiddo
Upload(Object src,EventArgs e)
{
HttpPostedFile hpf = UploadFile.PostedFile;
FileName.Text = hpf.FileName;
FileSize.Text = hpf.ContentLength.ToString();
//取得文件名(不含路径)
char[] de = {'//'};
string[] AFilename = hpf.FileName.Split(de);
string strFilename = AFilename[AFilename.Length-1];
rname.Text = strFilename;
hpf.SaveAs(Server.MapPath(".")+"//"+strFilename);
}
</script>
<html>
<head>
<title>上传单个文件</title>
</head>
<body>
<form Enctype="multipart/form-data" runat="server">
<b>上传单个文件示例</b>
<hr>
请选择文件上传:<input type="file" id="UploadFile" runat="server"><br>
<input type="submit" value="上传" OnServerClick="DoUpload" runat="server">
<hr>
上传文件名:<asp:Label id="FileName" Text="尚未上传" runat="server" /><br>
上传文件大小:<asp:Label id="FileSize" Text="尚未上传" runat="server" /><br>
真实文件名:<asp:Label id="rname" Text="尚未上传" runat="server" />
</form>
</body>
</html>