zoukankan      html  css  js  c++  java
  • 上传文件asp.net c#

    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;
    }


    }

    天道酬勤,厚积薄发。 君子之行,静以修身,俭以养德。 非淡泊无以明志,非宁静无以致远。 如有恒,何须三更起,半夜眠;最怕莫,三天打鱼两天晒网,竹篮打水一场空。
  • 相关阅读:
    二维码
    struts2 result type=(chain、dispatcher、redirect、redirect-action)
    hibernate bean注解
    js uploadify
    2进制转化成字符串
    server.xml
    html css
    页面乱码
    java class 路径问题
    table th td 宽度
  • 原文地址:https://www.cnblogs.com/houweidong/p/12263242.html
Copyright © 2011-2022 走看看