上传文件

//获取用户输入 文件标题、备注
string file_name = TxtTitile.Text.Trim();
string file_content = Txtcontent.Text.Trim();
string username = "测试用户";//测试用的


string name = FileUpload1.FileName;//获取已上传文件的名字
string size = FileUpload1.PostedFile.ContentLength.ToString();//获取已上传文件的大小
string type = FileUpload1.PostedFile.ContentType;//获取已上传文件的MIME内容类型,但是不直观
string type2 = name.Substring(name.LastIndexOf("." )+ 1);//文件的后缀名
string ipath = Server.MapPath("file") + "\\" + name;//获取文件上传的实际路径
string fpath = Server.MapPath("upfile") + "\\" + name;//获取文件上传的实际路径
// string wpath = "file\\" + name;//写入到数据库去的虚拟路径
string wpath1 = "~/file/" + name;//写入到数据库去的虚拟路径
// Response.Write(wpath1);

//判断文件名是否含有【点】号
if (type2.Length<0)
{
//为假,弹出消息框提示用户
AlertMsg("你上传文件不合规矩!");
}
else
{
//下面判断文件的格式
if (1==1)
{
if (wpath1 == null)
{
AlertMsg("上传路径不能为空");
}
//将文件保存到path这个路径
FileUpload1.SaveAs(ipath);


//存入数据库
SqlHelper.Execsql(file_name, file_content, wpath1, username);

// 弹出成功消息框
AlertMsg("上传成功!");
bind();
//清空数据
TxtTitile.Text = "";
Txtcontent.Text = "";



}
else
{
AlertMsg("上传失败!");

}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值