文件上传

来源:互联网 发布:日本人的交友软件 编辑:程序博客网 时间:2024/06/05 10:44
  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);    }

0 0