/// <summary> /// 上传教师excel文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Import_Click(object sender, EventArgs e) { try { if (FileUp.HasFile) { //string UploadPath = "c:\\wyr\\UploadFile\\"; //上传文件路径 string UploadPath = System.Configuration.ConfigurationManager.ConnectionStrings["UploadPath"].ConnectionString;//上传文件路径 string serverPath = Server.MapPath("~" + UploadPath); //2.判断文件目录是否存在 if (!Directory.Exists(serverPath)) { Directory.CreateDirectory(serverPath); } string FileClientPath = FileUp.PostedFile.FileName; FileInfo file = new FileInfo(FileClientPath); string FileExtensionName = file.Extension.ToLower(); //文件后缀名 if (FileExtensionName != ".xlsx" && FileExtensionName != ".xls") { return; } string NewName = DateTime.Now.ToString("yyyyMMddhhmmssfff") + FileExtensionName; // 文件名称,当前时间(yyyyMMddhhmmssfff) string CompleteFilePath = UploadPath + NewName; // 服务器端文件路径 FileUp.SaveAs(CompleteFilePath); // 使用 SaveAs 方法保存文件 //this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "", "<script>ImportTeacher('" + CompleteFilePath + "');</script>", true); CompleteFilePath = CompleteFilePath.Replace("\\", "\\\\"); //增加转义字符 ,因为调用js方法在会转义一次字符串 Page.RegisterStartupScript("a", "<script>ImportTeacher('" + CompleteFilePath + "');</script>"); } } catch (Exception) { } }
protected void Save_Click(object sender, EventArgs e) { int vitri = Int32.Parse(ViTri.Text); string IsUpdate = isUpdate.Value; /* UTpdate*/ if (IsUpdate == "update") { int id = int.Parse(newsID.Value); if (FileUp.HasFile) { string extension = System.IO.Path.GetExtension(FileUp.FileName); if (extension == ".jpg" || extension == ".png" || extension == ".gif") { string path = Server.MapPath("~/uploads/slides//"); FileUp.SaveAs(path + FileUp.FileName); string Anh = "~/uploads/slides/" + FileUp.FileName; slides.update(id, Anh, vitri); } else { return; } } else { slides.update1(id, vitri); } } /* Thêm mới */ else { if (FileUp.HasFile) { string extension = System.IO.Path.GetExtension(FileUp.FileName); if (extension == ".jpg" || extension == ".png" || extension == ".gif") { string path = Server.MapPath("~/uploads/slides//"); FileUp.SaveAs(path + FileUp.FileName); string Anh = "~/uploads/slides/" + FileUp.FileName; slides.insert(Anh, vitri); } else { return; } } else { return; } } Response.Redirect(Request.Url.ToString()); }
protected void Submit_Click(object sender, EventArgs e) { String filename = Path.GetFileName(FileUp.FileName); FileUp.SaveAs(Server.MapPath("~/Upload/") + filename); BLL obj = new BLL(); BLL.Magazine(DD1.SelectedItem.Value, Fdate.Text.Trim(), Tdate.Text.Trim(), DD2.SelectedItem.Value, DD3.SelectedItem.Value, DD4.SelectedItem.Value, RB1.Text.Trim(), TB4.Text.Trim(), filename); }
/// <summary> /// Action taken when the upload button is pressed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnUpload_Click(object sender, EventArgs e) { labelMessage.ForeColor = System.Drawing.Color.Black; // Check if any file was uploaded if (FileUp.HasFile) { string FileName = Path.GetFileName(FileUp.PostedFile.FileName); string Extension = Path.GetExtension(FileUp.PostedFile.FileName); // Check if the file is the required format. if (Extension.Contains("xls")) { // Check if the same file was already uploaded if (!wasUploaded(FileName)) { // Insert the file name if (insertFileName(FileName)) { string FolderPath = ConfigurationManager.AppSettings["FolderPath"]; string FilePath = Server.MapPath(FolderPath + FileName); FileUp.SaveAs(FilePath); // Save the excel file onto the server UploadFile(FileName); } else { labelMessage.ForeColor = System.Drawing.Color.Red; labelMessage.Text = "The report could not be uploaded."; } } else { labelMessage.ForeColor = System.Drawing.Color.Red; labelMessage.Text = "The report has already been uploaded."; } } else { labelMessage.ForeColor = System.Drawing.Color.Red; labelMessage.Text = "Wrong format of the file. The expected file should be a Microsoft Excel."; } } else { labelMessage.ForeColor = System.Drawing.Color.Red; labelMessage.Text = "No file was chosen."; } }
protected void BtnUpload_Click(object sender, EventArgs e) { string FileName = TxtFileName.Text.Trim(); uploadF up = new uploadF(); string UploadFile = up.savefile(FileUp); string fileName = Path.GetFileNameWithoutExtension(UploadFile); string fileExtension = Path.GetExtension(UploadFile); string Key = HiddenKey.Value; //Build the File Path for the original (input) and the encrypted (output) file. string input = Server.MapPath("~/temp/") + fileName + fileExtension; string output = Server.MapPath("~/temp/") + fileName + "_enc" + fileExtension; //Save the Input File, Encrypt it and save the encrypted file in output path. FileUp.SaveAs(input); this.Encrypt(input, output, Key); string uploadFilepath = fileName + "_enc" + fileExtension; int flag = 0; if (DataAccess.GetInstance().Files_update_File(Convert.ToInt32(HiddenFID.Value), uploadFilepath)) { Utils.ShowAlertMessage("File Updated Successfully"); flag = 1; } else { Utils.ShowAlertMessage("Server Down Try Later"); } if (input != null || input != string.Empty) { if ((System.IO.File.Exists(input))) { System.IO.File.Delete(input); } } if (flag.Equals(1)) { Response.Redirect("UpdateFile.aspx"); } }
protected void BtnSubmit_Click(object sender, EventArgs e) { string FileName = TxtFileName.Text.Trim(); uploadF up = new uploadF(); string UploadFile = up.savefile(FileUp); int TPA = Convert.ToInt32(DropDownTPA.SelectedValue); string Key = GetKeyGenerate(9); string fileName = Path.GetFileNameWithoutExtension(UploadFile); string fileExtension = Path.GetExtension(UploadFile); //Build the File Path for the original (input) and the encrypted (output) file. string input = Server.MapPath("~/temp/") + fileName + fileExtension; string output = Server.MapPath("~/temp/") + fileName + "_enc" + fileExtension; //Save the Input File, Encrypt it and save the encrypted file in output path. FileUp.SaveAs(input); this.Encrypt(input, output, Key); string uploadFilepath = fileName + "_enc" + fileExtension; string User = Session["Email"].ToString(); if (DataAccess.GetInstance().Files_add_File(User, TPA, FileName, uploadFilepath, Key)) { Utils.ShowAlertMessage("File Uploaded Successfully"); TxtFileName.Text = ""; DropDownTPA.ClearSelection(); } else { Utils.ShowAlertMessage("Server Down Try Later"); } if (input != null || input != string.Empty) { if ((System.IO.File.Exists(input))) { System.IO.File.Delete(input); } } }
protected void Add_Click(object sender, EventArgs e) { RightImage na = new RightImage(); NewsImageBLL newsimagebll = new NewsImageBLL(); string newname = ""; if (FileUp.HasFile) { FileInfo file = new FileInfo(FileUp.PostedFile.FileName); if (file.Extension.ToLower() != ".bmp" && file.Extension.ToLower() != ".jpg" && file.Extension.ToLower() != ".jpeg" && file.Extension.ToLower() != ".png" && file.Extension.ToLower() != ".gif") { Response.Write("<script>alert('上传的资料格式应为bmp/jpg/jpeg/png/gif格式');history.back(-1);</script>"); return; } string filename = FileUp.PostedFile.FileName; filename = System.IO.Path.GetFileName(filename); //改文件名 int index = filename.LastIndexOf("."); string lastName = filename.Substring(index, filename.Length - index);//获得文件后缀类型 //新文件名称,以时间年月日时分秒作为文件名 newname = "RightImage" + DateTime.Now.ToString("yyyyMMddhhmmss") + lastName; double size = FileUp.PostedFile.ContentLength; string webFilePath = Server.MapPath("/NewsImages/" + newname); if (!File.Exists(webFilePath)) { FileUp.SaveAs(webFilePath); // 使用 SaveAs 方法保存文件 System.Drawing.Image image = System.Drawing.Image.FromFile(webFilePath); float a = image.Width / image.Height; if (a > 5) { image.Dispose(); File.Delete(webFilePath); Response.Write("<script>alert('高宽比例不合适');</script>"); return; } System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image, 168, 155); string path = Server.MapPath("/IndexImages/" + newname); if (!File.Exists(path)) { bmp.Save(path); } image.Dispose(); bmp.Dispose(); } else { Response.Write("<script>alert('上传失败,请重试!')</script>"); return; } } na.Url = newname; na.AddDate = Convert.ToDateTime(TxtDate.Text); string title = Server.HtmlEncode(TxtTitle.Text.Trim()); na.Title = title; if (newsimagebll.Add1(na)) { Response.Write("<script>alert('添加成功');window.location.href='RightMgr.aspx';</script>"); } else { Response.Write("<script>alert('添加失败');history.back();</script>"); } }
protected void Save_Click(object sender, EventArgs e) { object id = Request.QueryString["id"];//有待改善不安全 RightImage ni = new RightImage(); NewsImageBLL newsimagebll = new NewsImageBLL(); string title = Server.HtmlEncode(TxtTitle.Text.Trim()); ni.AddDate = Convert.ToDateTime(TxtDate.Text); ni.Title = title; ni.Id = id; string name = this.Image1.ImageUrl.Substring(14);//原来图片的URL if (FileUp.PostedFile.ContentLength == 0) { ni.Url = name; } else { FileInfo file1 = new FileInfo(FileUp.PostedFile.FileName); if (file1.Extension.ToLower() != ".bmp" && file1.Extension.ToLower() != ".jpg" && file1.Extension.ToLower() != ".jpeg" && file1.Extension.ToLower() != ".png" && file1.Extension.ToLower() != ".gif") { Response.Write("<script>alert('上传的资料格式应为bmp/jpg/jpeg/png/gif格式');history.back(-1);</script>"); return; } string webFilePath = Server.MapPath("~/NewsImages/" + name);//用来删除原有的图片 string indexpath = Server.MapPath(this.Image1.ImageUrl); string filename = FileUp.PostedFile.FileName; filename = System.IO.Path.GetFileName(filename); //改文件名 int index = filename.LastIndexOf("."); string lastName = filename.Substring(index, filename.Length - index);//获得文件后缀类型 //新文件名称,以时间年月日时分秒作为文件名 string newname = "NewImage" + DateTime.Now.ToString("yyyyMMddhhmmss") + lastName; string newpath = Server.MapPath("/NewsImages/" + newname);//用来保存新上传的图片 string newindexpath = Server.MapPath("/IndexImages/" + newname); System.IO.FileInfo file = new System.IO.FileInfo(webFilePath); System.IO.FileInfo indexfile = new System.IO.FileInfo(indexpath); if (file.Exists) { file.Delete();//删除 } if (indexfile.Exists) { indexfile.Delete();//删除 } if (!File.Exists(newpath)) { FileUp.SaveAs(newpath);// 使用 SaveAs 方法保存文件 System.Drawing.Image image = System.Drawing.Image.FromFile(newpath); float a = image.Width / image.Height; if (a > 5) { image.Dispose(); File.Delete(newpath); Response.Write("<script>alert('高宽比例不合适');</script>"); return; } System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(image, 168, 155); if (!File.Exists(newindexpath)) { bmp.Save(newindexpath); } image.Dispose(); bmp.Dispose(); } ni.Url = newname; } if (newsimagebll.Update1(ni)) { Response.Write("<script>alert('更新成功');window.location.href='RightMgr.aspx';</script>"); } else { Response.Write("<script>alert('更新失败');history.back();</script>"); } }
protected void Add_Click(object sender, EventArgs e) { DownAttach da = new DownAttach(); DownAttachBLL downattachbll = new DownAttachBLL(); string filename = FileUp.PostedFile.FileName; filename = System.IO.Path.GetFileName(filename); //改文件名 int index = filename.LastIndexOf("."); string lastName = filename.Substring(index, filename.Length - index);//获得文件后缀类型 //新文件名称,以时间年月日时分秒作为文件名 string name = DateTime.Now.ToString("yyyyMMddhhmmss") + lastName; //name = FileUp.FileName; // 客户端文件路径 string webFilePath = Server.MapPath("/Attach/" + name); // 服务器端文件路径 if (FileUp.HasFile) { //以下是上传资料的格式检验 FileInfo file = new FileInfo(FileUp.PostedFile.FileName); if (file.Extension.ToLower() != ".doc" && file.Extension.ToLower() != ".txt" && file.Extension.ToLower() != ".zip" && file.Extension.ToLower() != ".rar" && file.Extension.ToLower() != ".pdf") { Response.Write("<script>alert('上传的资料格式应为doc/txt/zip/rar/pdf格式');history.back(-1);</script>"); return; } //double size = FileUp.PostedFile.ContentLength;//文件大小 //if (size >= 20480000) //{ // Response.Write("<script>alert('上传失败!(资料容量请不要超过20MB)');history.back();</script>"); // return; //} if (!File.Exists(webFilePath)) { FileUp.SaveAs(webFilePath); // 使用 SaveAs 方法保存文件 } else { Response.Write("<script>alert('上传失败,请重试!')</script>"); } } else { Response.Write("文件名称为空,请填写要上传文件的名称"); return; } da.AddDate = Convert.ToInt32(TxtDate.Text.Trim() ); da.Writer = Server.HtmlEncode(TxtWriter.Text.Trim()); da.Title = Server.HtmlEncode(TxtTitle.Text.Trim()); da.FileSaveName = name; da.FileId = TextBox1.Text.Trim(); if (classification.SelectedItem.Text == "自然版过刊") { da.Cid = 1; if (classfenqi.SelectedItem.Text == "第一期") { da.Type = 1.1F; } else if (classfenqi.SelectedItem.Text == "第二期") { da.Type = 1.2F; } else if (classfenqi.SelectedItem.Text == "第三期") { da.Type = 1.3F; } else if (classfenqi.SelectedItem.Text == "第四期") { da.Type = 1.4F; } else if (classfenqi.SelectedItem.Text == "第五期") { da.Type = 1.5F; } else if (classfenqi.SelectedItem.Text == "第六期") { da.Type = 1.6F; } } else if (classification.SelectedItem.Text == "社科版过刊") { da.Cid = 2; if (classfenqi.SelectedItem.Text == "第一期") { da.Type = 2.1F; } else if (classfenqi.SelectedItem.Text == "第二期") { da.Type = 2.2F; } else if (classfenqi.SelectedItem.Text == "第三期") { da.Type = 2.3F; } else if (classfenqi.SelectedItem.Text == "第四期") { da.Type = 2.4F; } else if (classfenqi.SelectedItem.Text == "第五期") { da.Type = 2.5F; } else if (classfenqi.SelectedItem.Text == "第六期") { da.Type = 2.6F; } } //else if (classification.SelectedItem.Text == "BBS资料") //{ da.Cid = 4; } else { da.Cid = 3; } da.Count = 1; if (downattachbll.Add(da)) { Response.Write("<script>alert('添加成功');window.location.href='DownMgr.aspx';</script>"); } else { Response.Write("<script>alert('添加失败');history.back();</script>"); } }
protected void Save_Click(object sender, EventArgs e) { string tieuDe = TieuDe.Text; string nguoiDang = NguoiDang.Text; DateTime ngayDang = DateTime.Now; string chiTiet = CKEditor1.Text; int id_DanhMuc = int.Parse(DanhMuc.SelectedValue); string IsUpdate = isUpdate.Value; /* UTpdate*/ if (IsUpdate == "update") { int id = int.Parse(newsID.Value); if (FileUp.HasFile) { string extension = System.IO.Path.GetExtension(FileUp.FileName); /* string myScript = "alert('" + extension + "');"; * ClientScriptManager cs = Page.ClientScript; * cs.RegisterClientScriptBlock(Page.GetType(), "myAlert", myScript, true);*/ if (extension == ".jpg" || extension == ".png" || extension == ".gif") { string path = Server.MapPath("~/uploads/news//"); FileUp.SaveAs(path + FileUp.FileName); string Anh = "~/uploads/news/" + FileUp.FileName; news.update(id, tieuDe, Anh, chiTiet, nguoiDang, ngayDang, id_DanhMuc); /* string myScript = "alert('" + Anh + "');"; * ClientScriptManager cs = Page.ClientScript; * cs.RegisterClientScriptBlock(Page.GetType(), "myAlert", myScript, true);*/ } else { return; } } else { news.update1(id, tieuDe, chiTiet, nguoiDang, ngayDang, id_DanhMuc); } } /* Thêm mới */ else { if (FileUp.HasFile) { string extension = System.IO.Path.GetExtension(FileUp.FileName); if (extension == ".jpg" || extension == ".png" || extension == ".gif") { string path = Server.MapPath("~/uploads/news//"); FileUp.SaveAs(path + FileUp.FileName); string Anh = "~/uploads/news/" + FileUp.FileName; news.insert(tieuDe, Anh, chiTiet, nguoiDang, ngayDang, id_DanhMuc); /* string myScript = "alert('" + AdminRequestTime + "');"; * ClientScriptManager cs = Page.ClientScript; * cs.RegisterClientScriptBlock(Page.GetType(), "myAlert", myScript, true);*/ } else { return; } } else { return; } } Response.Redirect(Request.Url.ToString()); /* string myScript = "alert('" + "');"; * ClientScriptManager cs = Page.ClientScript; * cs.RegisterClientScriptBlock(Page.GetType(), "myAlert", myScript, true);*/ }
protected void Save_Click(object sender, EventArgs e) { object id = Request.QueryString["id"];//有待改善不安全 DownAttach da = new DownAttach(); DownAttachBLL downbll = new DownAttachBLL(); // da.AddDate = Convert.ToInt32(dr["AddDate"].ToString()); ; da.Writer = Server.HtmlEncode(TxtWriter.Text.Trim()); da.Title = Server.HtmlEncode(TxtTitle.Text.Trim()); da.Id = id; if (classification.SelectedItem.Text == "自然版过刊") { da.Cid = 1; } else if (classification.SelectedItem.Text == "社科版过刊") { da.Cid = 2; } //else if (classification.SelectedItem.Text == "TRIZ书籍") //{ // da.Cid = 3; //} //else if (classification.SelectedItem.Text == "BBS资料") //{ // da.Cid = 4; //} if (FileUp.PostedFile.ContentLength == 0) { da.FileSaveName = TxtFileName.Text; } else { //以下是上传资料的格式检验 FileInfo file1 = new FileInfo(FileUp.PostedFile.FileName); if (file1.Extension.ToLower() != ".doc" && file1.Extension.ToLower() != ".txt" && file1.Extension.ToLower() != ".zip" && file1.Extension.ToLower() != ".rar") { Response.Write("<script>alert('上传的资料格式应为doc/txt/zip/rar格式');history.back(-1);</script>"); return; } string filename = FileUp.PostedFile.FileName; filename = System.IO.Path.GetFileName(filename); //改文件名 int index = filename.LastIndexOf("."); string lastName = filename.Substring(index, filename.Length - index);//获得文件后缀类型 //新文件名称,以时间年月日时分秒作为文件名 string name = TxtTitle.Text.Trim() + DateTime.Now.ToString("hhmmss") + lastName; string webFilePath = Server.MapPath("~/Attach/" + TxtFileName.Text); //用来删除原有的资料 string newpath = Server.MapPath("~/Attach/" + name); //用来保存新上传的资料 System.IO.FileInfo file = new System.IO.FileInfo(webFilePath); if (file.Exists) { file.Delete();//删除 } if (!File.Exists(newpath)) { FileUp.SaveAs(newpath); // 使用 SaveAs 方法保存文件 } da.FileSaveName = name; } if (downbll.Update(da)) { Response.Write("<script>alert('修改成功');window.location.href='DownMgr.aspx';</script>"); } else { Response.Write("<script>alert('修改失败');history.back();</script>"); } }
protected void BtnAdd_Click(object sender, EventArgs e) { if (DListDownloadsTypes.SelectedValue == "-1") { Config.MsgBoxAjax("Sənədin növünü seçin!"); return; } if (string.IsNullOrEmpty(TxtName.Text)) { Config.MsgBoxAjax("Sənədin adını qeyd edin!"); return; } string FileName = TxtName.Text.ClearTitle(); if (DALC.CheckDownloadsByName(FileName, _DownloadsID)) { Config.MsgBoxAjax("Bu sənəd adı, artıq istifadə edilib!"); return; } if (_DownloadsID == 0) { if (!FileUp.HasFile) { Config.MsgBoxAjax("Fayl seçin!"); return; } } if (DListStatus.SelectedValue == "-1") { Config.MsgBoxAjax("Sənədin statusunu qeyd edin!"); return; } string FileType = ""; decimal FileContentLength = 0; string AllowType = "-xls-xlsx-doc-docx-pdf-rar-zip-jpg-jpeg-png-txt-rtf-"; if (FileUp.HasFile) { FileType = Path.GetExtension(FileUp.PostedFile.FileName); //FileName = string.Format("{0}{1}", FileName, FileType); FileContentLength = FileUp.PostedFile.ContentLength / 1024; if (AllowType.IndexOf(string.Format("-{0}-", FileType.Trim('.'))) < 0) { Config.MsgBoxAjax("Fayl formatı düzgün deyil!"); return; } if (FileUp.PostedFile.CheckIfFileIsExecutable()) { Config.MsgBoxAjax("Fayl formatı düzgün deyil!"); return; } if (!FileUp.PostedFile.CheckFileContentLength(20)) { Config.MsgBoxAjax("Faylın həcmi ən cox 20MB ola bilər!"); return; } if (string.IsNullOrEmpty(FileName) || string.IsNullOrEmpty(FileName) || FileContentLength == 0) { Config.MsgBoxAjax("Xətalı fayl!"); return; } try { FileUp.SaveAs(Server.MapPath(string.Format(_filePath, FileName + FileType))); } catch (Exception er) { DALC.ErrorLogs(string.Format("Sənədlər bölməsində fayl yüklənərkən xəta: {0}", er.Message)); Config.MsgBoxAjax("Fayl yüklənərkən xəta baş verdi!"); return; } } Dictionary <string, object> Dictionary = new Dictionary <string, object>(); Dictionary.Add("DownloadsTypesID", int.Parse(DListDownloadsTypes.SelectedValue)); Dictionary.Add("DataID", 0); Dictionary.Add("DisplayName", TxtName.Text); if (FileUp.HasFile) { Dictionary.Add("FileName", FileName); Dictionary.Add("FileType", FileType); Dictionary.Add("ContentLength", FileContentLength); } Dictionary.Add("Description", TxtDescription.Text); Dictionary.Add("IsActive", int.Parse(DListStatus.SelectedValue)); int Result; if (_DownloadsID == 0) { Dictionary.Add("UsersID", DALC._GetUsersLogin.ID); Dictionary.Add("DownloadsQualityTypesID", (int)Tools.DownloadsQualityTypes.Qiymətləndirilməyib); Dictionary.Add("Data_Dt", DateTime.Now); Dictionary.Add("Add_Dt", DateTime.Now); Dictionary.Add("Add_Ip", Request.UserHostAddress.IPToInteger()); Result = DALC.InsertDatabase(Tools.Table.Downloads, Dictionary); if (Result < 1) { Config.MsgBoxAjax(Config._DefaultErrorMessages); return; } } else { Dictionary.Add("WhereID", _DownloadsID); Result = DALC.UpdateDatabase(Tools.Table.Downloads, Dictionary); if (Result < 1) { Config.MsgBoxAjax(Config._DefaultErrorMessages); return; } } Config.MsgBoxAjax(Config._DefaultSuccessMessages, "/tools/downloads"); }