前台页面使用ASP控件:<asp:FileUpload ID="FileUpload" runat="server" Style="margin-left: 515px" />//上传控件

          <asp:Button ID="upLoad" runat="server" Text="上传文件" onclick="upLoad_Click" />点击button,触发上传事件

 protected void upLoad_Click(object sender, EventArgs e)
    {
        bool result = FileUpload.HasFile;
        if (result == true)
        {
            string full = FileUpload.FileName;
            string[] fn = full.Split('.');
            ];//文件名字
            ];//文件类型
            string size = FileUpload.PostedFile.ContentLength.ToString();//上传文件的大小
            string name = Request.QueryString["name"].ToString();//接受传参的人
            string date = DateTime.Now.ToString("yyyyMMddhhmmssfff"); //获取上传文件的时间。
            //将上传的文件保存到指定的目录下
            string path = Server.MapPath("~") + "\\" + "Upload\\" + date + '.' + type;
            FileUpload.SaveAs(path.Trim());
            SQLHelper s = new SQLHelper(sqlstring);
            string sql = @"select TITLE from dbo.SMTUsers where USERID=N'" + name + "';";
            DataTable dt = s.Query(sql);
            ][].ToString();//获取上传人的上传角色
            SQLHelper sh = new SQLHelper(sqlstring);
            string str = @"insert into dbo.UploadFiles values(N'" + date + fileName + "',N'" + type + "',N'" + size + "',N'" + role + "',N'" + name + "','" + date + "','" + fid + "',N'" + fileName + "');";
            sh.Execute(str);
            Bind();
        }
    }

选中gridview中,已上传了的附件。点击删除按钮,删除附件。

 protected void Button1_Click(object sender, EventArgs e)
    {
        ; i < GridView1.Rows.Count; i++)
        {

            bool result = ((CheckBox)GridView1.Rows[i].FindControl("chk")).Checked;
            if (result == true)
            {
                ].Text.Trim();
                ].Text.Trim();
                ].Text.Trim();
                string path = Server.MapPath("~") + "\\" + "Upload\\" + date + '.' + type;
                File.Delete(path);
                SQLHelper s = new SQLHelper(sqlstring);
                string sql = @"delete dbo.UploadFiles where FILE_NAME=N'" + date + name + "'";
                s.Execute(sql);
            }
        }
        Bind();
    }
04-17 09:47
查看更多