嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 4 元微信扫码支付:4 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
上传成功后 将图片会保存在File目录下,成功截图如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
if (FileUpload1.PostedFile.FileName == "")
{
Label1.Text = "要上传的文件不允许为空!";
return;
}
else
{
string filepath = FileUpload1.PostedFile.FileName;//取文件路径
string filename = filepath.Substring(filepath.LastIndexOf("\\") 1);//取文件名
string serverpath = Server.MapPath("File/") filename;//合成上传路径
FileUpload1.PostedFile.SaveAs(serverpath);//上传文件
Label1.Text = "上传成功!";
}
}
catch (Exception error)
{
Label1.Text = "处理发生错误!原因:" error.ToString();
}
}
}
}