Add a file browse HTML control. Right click and select 'Run as Server Control'. Add a button. So you have something like this:
<input type="file" runat="server" ID="File1" /><asp:Button runat="server" ID="Button1" />
Double click the button and add the following code.
private void Button1_Click(object sender, System.EventArgs e)
{
string strFilename;
try
{
strFilename = File1.PostedFile.FileName;
strFilename = System.IO.Path.GetFileName(strFilename);
File1.PostedFile.SaveAs(@"f:/"+strFilename);
}
catch(Exception ex)
{
Response.Write(ex);
}
}
本文介绍如何使用ASP.NET实现文件上传功能。具体步骤包括:添加文件浏览HTML控件并设置为服务器控件,添加按钮控件,双击按钮添加事件处理程序实现文件保存到指定路径的功能。

120

被折叠的 条评论
为什么被折叠?



