附件的上传

public string col = "info";//设置数据库表名

 #region 添加处理,上传文件并写入数据
    protected void btnOk_Click(object sender, System.EventArgs e)
    {
        int classid = 0;
        classid = pub.GetAjaxClassId(Request.Form["ddl1"], Request.Form["ddl2"], Request.Form["ddl3"], Request.Form["ddl4"], Request.Form["ddl5"]);
        string ti = DateTime.Now.ToString("yyyymmddhhmmss");
        string path = Server.MapPath("~/Service/GraduateChannel/");
        string name = FileUpload1.FileName;//获取文件名
        string type = name.Substring(name.LastIndexOf(".") + 1);      //获取文件类型
        string ipath = path + name;      //获取文件路径 
        string wpath = "slave//" + name;
        if (type == "zip" || type == "rar")
        {
            FileUpload1.PostedFile.SaveAs(path + "" + wpath);
            this.name.Value = name;
            string sql = "";
            if (id > 0)
            {
                sql = "insert into Upfile (Oname,Nname,Filepath,Addtime,Classid) values (@Oname,@Nname,@Filepath,@Addtime,@Classid)";
            }
            else
            {
                sql = "update " + col + " set Classid=@classid,Oname=@title,Nname=@name,Addtime=@Addtime,Filepath=@Filepath where [Infoid]=@id";
            }
            SqlCommand cmd = this.dbc.GetCommandBySql(sql);
            cmd.Parameters.Add("@id", SqlDbType.Int).Value = this.id;
            cmd.Parameters.Add("@Oname", SqlDbType.VarChar).Value = FileUpload1.FileName;
            cmd.Parameters.Add("@Nname", SqlDbType.VarChar).Value = name;
            cmd.Parameters.Add("@Filepath", SqlDbType.VarChar).Value = path + "" + wpath;
            cmd.Parameters.Add("@Addtime", SqlDbType.DateTime).Value = DateTime.Now.ToShortDateString();
            cmd.Parameters.Add("@Classid", SqlDbType.Int).Value = classid;
            cmd.Connection.Open();
            int rows = cmd.ExecuteNonQuery();
            cmd.Connection.Close();
            cmd.Connection.Dispose();
            cmd.Dispose();
            AddInfo.Enabled = false;
            if (rows <= 0)
            {
                Response.Write("<script>alert('文件格式不对!');</script>");
                return;
            }
            pubfun.RegisterStartupScript(Page, "PAGE", "window.location.href='" + "Info.aspx?ChannelId=" + this.channelid.ToString() + "';");
        }
        else
        {
            Response.Write("<script>alert('文件格式不对!');</script>");
        }
       
    }
    #endregion

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值