//保存 protected void Button_Save_Click(object sender, EventArgs e) { if (this.Session["hyuid"].ToString() == "") this.Response.Redirect("../login.aspx"); string ls_tip = "保存成功!"; //新文档时 string ls_attsize = ""; string str_path = ""; string lspath = ""; string lsguid = ""; string lsurl = ""; string lsfilename = ""; string lshy_fatherfield = System.Guid.NewGuid().ToString(); lsfilename = FileUpload1.FileName; HyoaClass.Hyoa_global Hyoa_global = new HyoaClass.Hyoa_global(); HyoaClass.Hyoa_ntkotemplateFile Hyoa_ntkotemplateFile = new HyoaClass.Hyoa_ntkotemplateFile(); if (this.txtop.Value == "add") { lsguid = Hyoa_global.GetRandom(); txtdocid.Value = lsguid; if (lsfilename != "") { string str_filename = Server.HtmlEncode(lsfilename); string extension = System.IO.Path.GetExtension(str_filename).ToLower(); if ((extension != ".doc") && (extension != ".docx")) { this.Response.Write("<script language=javascript>alert('请您上传word文档等格式的文件!');</script>"); return; } lshy_fatherfield = ""; ls_attsize = System.Convert.ToString(System.Convert.ToDouble(System.Convert.ToInt32(System.Convert.ToDouble(FileUpload1.PostedFile.ContentLength.ToString()) / 1024 / 1024 * 1000)) / 1000);//附件的大小 System.Console.WriteLine(txtdocid.Value); //SaveCommon(ls_path, ls_attsize, lsguid); //将附件上传到服务器目录下 lspath = Server.MapPath("~/");//虚拟目录的位置 lsurl = "NTKO\\templateFile"; //存放的文件夹 Directory.CreateDirectory(lspath + "\\" + lsurl); str_path = lspath + "\\" + lsurl + "\\" + lsguid + extension; FileUpload1.SaveAs(str_path); //插入数据库 Hyoa_ntkotemplateFile.templateFileid = txtdocid.Value; Hyoa_ntkotemplateFile.templateFilename = SignName.Value; Hyoa_ntkotemplateFile.templateFilesort = System.Int32.Parse(Sort.Value); Hyoa_ntkotemplateFile.templateFiletype = "发文"; Hyoa_ntkotemplateFile.templateFileurl = "templateFile/" + txtdocid.Value + extension; Hyoa_ntkotemplateFile.templateFileuserid = ""; Hyoa_ntkotemplateFile.templateFileusername = ""; Hyoa_ntkotemplateFile.Insert(); } else { this.Response.Write("<script>alert('请选择要上传的文件!');</script>"); } } else { if (lsfilename != "") { string str_filename = Server.HtmlEncode(lsfilename); string extension = System.IO.Path.GetExtension(str_filename).ToLower(); if ((extension != ".doc") && (extension != ".docx")) { this.Response.Write("<script language=javascript>alert('请您上传word文档等格式的文件!');</script>"); return; } lshy_fatherfield = ""; ls_attsize = System.Convert.ToString(System.Convert.ToDouble(System.Convert.ToInt32(System.Convert.ToDouble(FileUpload1.PostedFile.ContentLength.ToString()) / 1024 / 1024 * 1000)) / 1000);//附件的大小 System.Console.WriteLine(txtdocid.Value); //SaveCommon(ls_path, ls_attsize, lsguid); //将附件上传到服务器目录下 lspath = Server.MapPath("~/");//虚拟目录的位置 lsurl = "NTKO\\templateFile"; //存放的文件夹 Directory.CreateDirectory(lspath + "\\" + lsurl); str_path = lspath + "\\" + lsurl + "\\" + txtdocid.Value + extension; FileUpload1.SaveAs(str_path); } Hyoa_ntkotemplateFile.templateFileid = this.txtdocid.Value; Hyoa_ntkotemplateFile.templateFilename = SignName.Value; Hyoa_ntkotemplateFile.templateFileuserid = ""; Hyoa_ntkotemplateFile.templateFileusername = ""; Hyoa_ntkotemplateFile.templateFilesort = System.Int32.Parse(Sort.Value); Hyoa_ntkotemplateFile.Update(); } //处理完成后的提示及跳转 if (this.txtifpop.Value == "") { Response.Write("<script>alert('" + ls_tip + "');window.location='" + this.txturl.Value + "'</script>"); } else { Response.Write("<script>alert('" + ls_tip + "');self.close();</script>"); } }