码迷,mamicode.com
首页 > Windows程序 > 详细

上传文件asp.net c#

时间:2020-02-05 13:49:35      阅读:64      评论:0      收藏:0      [点我收藏+]

标签:cte   asp   turn   message   str   opd   net   star   选择   

protected void Button1_Click(object sender, EventArgs e)
{

if (this.DropDownList1.SelectedIndex > 0)
{
string xx = this.DropDownList1.SelectedValue.Trim();
string uptime = DateTime.Now.ToShortDateString().ToLower().ToString();
if (FileUpload1.PostedFile.ContentLength > 0)
{
string addfilename = DateTime.Now.ToString("yyyyMMddHHmmss") + FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf(".")).ToLower();
if (FileUpload1.PostedFile.ContentLength > 20000000)
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language=‘javascript‘ defer>alert(‘档案文件太大‘);</script>");
return;
}
else
{
if (new olecado().upfile(xx, addfilename, uptime))
{
FileUpload1.PostedFile.SaveAs(Server.MapPath("file/") + addfilename);
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language=‘javascript‘ defer>alert(‘文件已上传‘);</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language=‘javascript‘ defer>alert(‘文件上传失败‘);</script>");
}
}
}
else
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language=‘javascript‘ defer>alert(‘请选择文件后上传,详情咨询5227101!‘);</script>");
return;
}

}
else
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language=‘javascript‘ defer>alert(‘请选择单位后上传文件,详情咨询5227101!‘);</script>");
return;
}


}

上传文件asp.net c#

标签:cte   asp   turn   message   str   opd   net   star   选择   

原文地址:https://www.cnblogs.com/houweidong/p/12263242.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!