首页 > Web开发 > 详细

ASP.NET使用FileUpload上传文件

时间:2015-03-16 02:08:51      阅读:375      评论:0      收藏:0      [点我收藏+]

前台代码:

<asp:FileUpload ID="fuKeleyi" runat="server" />
<asp:Button ID="BtnUp" runat="server" onclick="BtnUp_Click" Text="上 传" />
<asp:Label ID="LabMsg" runat="server"></asp:Label>

?

后台C#代码:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace docnet
{
public partial class up : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void BtnUp_Click(object sender, EventArgs e)
{
if (fuKeleyi.HasFile)
{
string savePath = Server.MapPath("~/hovertreeupload/");//指定上传文件在服务器上的保存路径
//检查服务器上是否存在这个物理路径,如果不存在则创建
if (!System.IO.Directory.Exists(savePath))
{
System.IO.Directory.CreateDirectory(savePath);
}
savePath = savePath + "\\" + fuKeleyi.FileName;
fuKeleyi.SaveAs(savePath);
LabMsg.Text = string.Format("<a href=‘hovertreeupload/{0}‘>hovertreeupload/{0}</a>", fuKeleyi.FileName);
}
else
{
LabMsg.Text = "你还没有选择上传文件!";
}
}
}
}

?asp.net cms 源码:http://hovertree.codeplex.com/

?

http://hvt.iteye.com/blog/2182470

ASP.NET使用FileUpload上传文件

原文:http://hvt.iteye.com/blog/2192625

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!