文件上传

  public void  Fileurl(string name,string pa) {

        //获取上传文件名字
        string dn = this.DropDownList1.Text.Trim()+".doc";
        if (!Directory.Exists(pa))
        {
            //创建文件夹pa
            DirectoryInfo folder = Directory.CreateDirectory(pa);
        }
        else {
            string SNo = Session["name"].ToString();
            string DNo;
            string DN = this.DropDownList1.Text.Trim();
            switch (DN)
            {
                case "任务书": DNo = "1"; break;
                case "一稿": DNo = "2"; break;
                case "二稿": DNo = "3"; break;
                case "三稿": DNo = "4"; break;
                case "定稿": DNo = "5"; break;
                default: DNo = "6"; break;
            }
            Tool tool = new Tool();
            SqlConnection mycon = tool.Getconn();
            mycon.Open();
            string sql = "delete from StudebtData where SNo = '"+SNo+"' and DNo = '"+DNo+"'";
            SqlCommand mycmd = new SqlCommand(sql, mycon);
            mycmd.ExecuteNonQuery();
            mycon.Close();
            mycon.Open();
            string path = "~/Files/"+SNo+"/"+DN+".html";
           string pat = Server.MapPath(path);
            if (File.Exists(pat)) {
                FileInfo file = new FileInfo(pat);
                file.Delete();
            } 
           // Response.Write("<script>alert('文件上传成功');location='TiJ.aspx'</script>");
        }
        //保存文件
        FileUpload1.SaveAs(pa + "//" + dn);
    }
相关文章
相关标签/搜索