/// <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) { } }
public ActionResult UploadDemo(FormCollection form) { string file = form["file"]; string fse = FileUp.CreatUpFilePath(file, "/upload/", ".jpg|.png|.gif"); string msg = "失败"; try { // DirFile.CreateFile(Server.MapPath(fse.Split('|')[0] + fse.Split('|')[1])); bool isSuc = FileHelper.CreateFile(Server.MapPath(fse.Split('|')[0] + fse.Split('|')[1])); if (isSuc) { msg = "成功"; } } catch (Exception ex) { msg = "失败" + ex.ToString(); } finally { ViewBag.Message = msg; } return(View()); }
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); }
private void edit() { string title = this.txt_title.Text; if (title == null || title.Length <= 0) { JS.Alert("题目不能为空!"); return; } if (title.Length >= 255) { JS.Alert("题目过长!"); return; } string content = content2.Value; if (content == null || content.Length <= 0) { JS.Alert("内容不能为空!"); return; } string FilePath = ""; FilePath = File1.Value; if (FilePath.Length > 0) { FilePath = FileUp.meUpfile(this.File1, @"~\file\", true); FilePath = FilePath.Substring(FilePath.IndexOf('\\') + 1); } string sqlEdit = "update t_plat set ptitle=@ptitle,pcontent=@pcontent ,purl=@purl where id=" + UID; ArrayList insertValue = new ArrayList(); OleDbParameter ptitle = new OleDbParameter("@ptitle", OleDbType.VarChar); ptitle.Value = title; insertValue.Add(ptitle); OleDbParameter pcontent = new OleDbParameter("@pcontent", OleDbType.LongVarWChar); pcontent.Value = content; insertValue.Add(pcontent); OleDbParameter purl = new OleDbParameter("@purl", OleDbType.LongVarWChar); purl.Value = FilePath; insertValue.Add(purl); int p = AccessDb.ExecuteNon(sqlEdit, ref insertValue); JS.Alert("修改成功!"); }
public ActionResult update(int id, HttpPostedFileBase img1, FileUp model) { try { if (img1 != null) // Start Of First Outer If and this If Will Execute First { var ex = Path.GetExtension(img1.FileName); var data = (from t in db.FileUps where t.id == id select t.img).FirstOrDefault(); if (ex.Equals(".jpg") || ex.Equals(".png")) // Start Of First Inner If to check weather file contains .jpg or .png extension or not { int size = img1.ContentLength; if (size > 2000) // Start Of Seond Inner If to check weather file Size equal to 2 mb or not { string _path = Path.Combine(Server.MapPath("~/Content/Images"), data); img1.SaveAs(_path); tbl = (from t in db.FileUps where t.id == id select t).FirstOrDefault(); model.img = data; tbl.name = model.name; tbl.roll = model.roll; tbl.city = model.city; tbl.img = model.img; int k = db.SaveChanges(); ViewBag.data = "Data Is Updated"; return(RedirectToAction("list")); } else // End Of Seond Inner If { ViewBag.data = "Sorry File Is Greater Than 2 Mb"; } } else // End Of First inner If { ViewBag.data = "Please Select Image Only"; } } else // End Of First Outer If { ViewBag.data = "Please Select A File"; } } catch (Exception ex) { ViewBag.data = ex.Message; } return(View()); }
public async Task <IActionResult> FileUp(FileUp model) { if (ModelState.IsValid) { using (var stream = new FileStream(_env.WebRootPath + "/" + model.File.FileName, FileMode.Create)) { await model.File.CopyToAsync(stream); } } return(View(model)); }
//保存 protected void Button1_Click(object sender, EventArgs e) { if (Request.QueryString["type"] != null) { if (!FileUpload2.HasFile && string.IsNullOrEmpty(Label1.Text)) { Message("请上传详细材料", false); return; } //更新 int id = Convert.ToInt32(Request.QueryString["id"].ToString()); var Item = DB.Achievements.FirstOrDefault(a => a.Id == id);//获取对象 Item.AchTitle = AchTitle.Text; Item.AchType = AchType.Text; Item.AchContent = AchContent.Text; Item.AchTel = AchTel.Text; Item.Honor = Honor.Text; if (FileUpload2.HasFile) { string fileName = string.Empty; Item.AchFile = FileUp.SaveFile(FileUpload2, Server.MapPath("~/UpFile/"), ref fileName); Item.FileName = fileName; } Item.State = "待审"; //更新数据 DB.Entry(Item).State = EntityState.Modified; DB.SaveChanges(); } else { //添加数据 int personId = Convert.ToInt32(Session["PersonId"]); Achievements Item = new Achievements(); Item.PersonId = personId; Item.AchTitle = AchTitle.Text; Item.AchType = AchType.Text; Item.AchContent = AchContent.Text; Item.AchTel = AchTel.Text; Item.Honor = Honor.Text; Item.State = "待审"; Item.OperTime = DateTime.Now; string fileName = string.Empty; Item.AchFile = FileUp.SaveFile(FileUpload1, Server.MapPath("~/UpFile/"), ref fileName); Item.FileName = fileName; DB.Achievements.Add(Item); DB.SaveChanges(); } Message("/AchievementsPage/Manage.aspx", "保存成功"); }
public ActionResult update(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FileUp fileUp = db.FileUps.Find(id); if (fileUp == null) { return(HttpNotFound()); } return(View(fileUp)); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } FileUp = await _context.FileUp.FirstOrDefaultAsync(m => m.FileUpID == id); if (FileUp == null) { return(NotFound()); } return(Page()); }
/// <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."; } }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } FileUp = await _context.FileUp.FindAsync(id); if (FileUp != null) { _context.FileUp.Remove(FileUp); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
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); } } }
private void edit() { string Pic1 = ""; Pic1 = File1.Value; if (Pic1.Length > 0) { Pic1 = FileUp.meUpfile(this.File1, @"~\pic\", false); } if (Pic1 == "") { editNoPic(); } else { editPic(Pic1); } }
//保存 protected void Button1_Click(object sender, EventArgs e) { int id = Convert.ToInt32(Request.QueryString["id"].ToString()); int personId = Convert.ToInt32(Session["PersonId"]); ExpRecord Item = new ExpRecord(); Item.PersonId = personId; Item.ItemId = id; Item.ExpContent = ExpContent.Text; if (FileUpload3.HasFile) { string fileName = string.Empty; Item.UpFile = FileUp.SaveFile(FileUpload3, Server.MapPath("~/UpFile/"), ref fileName); Item.FileName = fileName; } Item.State = "正常"; Item.ExpTime = DateTime.Now; DB.ExpRecord.Add(Item); DB.SaveChanges(); Response.Redirect("/ExpRecordPage/Manage.aspx?id=" + id); }
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 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>"); } }
private void add() { string Pic1 = ""; Pic1 = File1.Value; if (Pic1.Length > 0) { Pic1 = FileUp.meUpfile(this.File1, @"~\pic\", false); } string title = this.txt_title.Text; if (title == null | title.Length <= 0) { JS.Alert("题目不能为空!"); return; } if (title.Length >= 255) { JS.Alert("题目过长!"); return; } string url = this.txt_Url.Text; if (url == null | url.Length <= 0) { JS.Alert("地址不能为空!"); return; } if (url.Length >= 255) { JS.Alert("地址过长!"); return; } string content = content2.Value; string strDateTime = this.txt_DateTime.Value; string sql = "insert into t_sample (ptitle,pcontent,purl,ppic,pdate) values(@ptitle,@pcontent,@url,@ppic,@pdate)"; ArrayList insertValue = new ArrayList(); OleDbParameter ptitle = new OleDbParameter("@ptitle", OleDbType.VarChar); ptitle.Value = title; insertValue.Add(ptitle); OleDbParameter pcontent = new OleDbParameter("@pcontent", OleDbType.LongVarWChar); pcontent.Value = content; insertValue.Add(pcontent); OleDbParameter purl = new OleDbParameter("@purl", OleDbType.VarChar); purl.Value = url; insertValue.Add(purl); OleDbParameter ppic = new OleDbParameter("@ppic", OleDbType.LongVarWChar); ppic.Value = Pic1; insertValue.Add(ppic); OleDbParameter pdate = new OleDbParameter("@pdate", OleDbType.Date); pdate.Value = strDateTime; insertValue.Add(pdate); int p = AccessDb.ExecuteNon(sql, ref insertValue); JS.Alert("添加成功!"); this.txt_title.Text = ""; this.txt_Url.Text = ""; this.content2.Value = ""; }
private void add() { string Pic1 = ""; Pic1 = File1.Value; if (Pic1.Length > 0) { Pic1 = FileUp.meUpfile(this.File1, @"~\pic\", false); } bool _pAnswered = false; string title = this.txt_title.Text; if (title == null || title.Length <= 0) { JS.Alert("问题题目不能为空!"); return; } if (title.Length >= 255) { JS.Alert("问题题目过长!"); return; } string content = content2.Value; if (content != null && content.Length > 0) { _pAnswered = true; } else { _pAnswered = false; } string sql = "insert into t_question (ptitle,pcontent,ppic,pdate,pAnswered) values(@ptitle,@pcontent,@ppic,@pdate,@pAnswered)"; ArrayList insertValue = new ArrayList(); OleDbParameter ptitle = new OleDbParameter("@ptitle", OleDbType.VarChar); ptitle.Value = title; insertValue.Add(ptitle); OleDbParameter pcontent = new OleDbParameter("@pcontent", OleDbType.LongVarWChar); pcontent.Value = content; insertValue.Add(pcontent); OleDbParameter ppic = new OleDbParameter("@ppic", OleDbType.LongVarWChar); ppic.Value = Pic1; insertValue.Add(ppic); OleDbParameter pdate = new OleDbParameter("@pdate", OleDbType.Date); pdate.Value = DateTime.Now; insertValue.Add(pdate); OleDbParameter pAnswered = new OleDbParameter("@pAnswered", OleDbType.Boolean); pAnswered.Value = _pAnswered; insertValue.Add(pAnswered); int p = AccessDb.ExecuteNon(sql, ref insertValue); JS.Alert("添加成功!"); this.txt_title.Text = ""; this.content2.Value = ""; }
protected void but_save_Click(object sender, EventArgs e) { string Pic1; Pic1 = this.File1.Value; string title = this.txt_title.Text; string url = this.txt_url.Text; string strSort = txt_sort.Text; int intsort = 0; try { intsort = int.Parse(this.txt_sort.Text); } catch { JS.Alert("序号必须为数字类型!"); return; } string strIsShow = this.drp_isUse.SelectedValue.ToString(); bool IsShow = (this.drp_isUse.SelectedValue == "是" ? true : false); if (UID != null && !UID.Equals(String.Empty)) { if (Pic1.Length > 0) { Pic1 = FileUp.meUpfile(this.File1, @"~\pic\", false); } if (Pic1 == "") { bool flag = updatSqlNoPic(title, url, intsort, IsShow, UID); if (flag) { JS.Alert("更新成功"); //Response.Redirect("b_topnewsList.aspx?id=news", false); } else { JS.Alert("更新失败"); } } else { bool flag = updatSql(Pic1, title, url, intsort, IsShow, UID); if (flag) { JS.Alert("成功"); } else { JS.Alert("失败"); } } } else { if (Pic1.Length > 0) { Pic1 = FileUp.meUpfile(this.File1, @"~\pic\", false); if (Pic1 == "") { JS.Alert("图片选择错误!"); } else { bool flag = AddSqlPic(Pic1, title, url, intsort, IsShow); if (flag) { JS.Alert("添加成功!"); } else { JS.Alert("添加失败!"); } } } else { JS.Alert("图片选择错误!"); } } }
public IActionResult FileUp() { var model = new FileUp(); return(View(model)); }
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"];//有待改善不安全 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>"); } }
public ActionResult Index(FileUp model, HttpPostedFileBase img1) { try { if (img1 != null) // Start Of First Outer If and this If Will Execute First { var ex = Path.GetExtension(img1.FileName); var FileName = Guid.NewGuid().ToString() + ex; if (ex.Equals(".jpg") || ex.Equals(".png")) // Start Of First Inner If to check weather file contains .jpg or .png extension or not { int size = img1.ContentLength; if (size >= 2000) // Start Of Seond Inner If to check weather file Size equal to 2 mb or not { string _path = Path.Combine(Server.MapPath("~/Content/Images"), FileName); img1.SaveAs(_path); model.img = FileName; tbl.name = model.name; tbl.roll = model.roll; tbl.city = model.city; tbl.img = model.img; db.FileUps.Add(model); int k = db.SaveChanges(); if (k > 0) { if (ModelState.IsValid) { var data = db.FileUps.Where(x => x.name.Equals(model.name)).FirstOrDefault(); if (data != null) { Session["Name"] = data.name.ToString(); Session["img"] = data.img.ToString(); return(RedirectToAction("dashboard")); } } } } else // End Of Seond Inner If { ViewBag.data = "Sorry File Is Smaller Than 2 Mb"; } } else // End Of First inner If { ViewBag.data = "Please Select Image Only"; } } else // End Of First Outer If { ViewBag.data = "Please Select A File"; } } catch (Exception ex) { ViewBag.data = ex.Message; } return(View()); }
protected void Button1_Click(object sender, EventArgs e) { string FilePath = ""; FilePath = File1.Value; if (FilePath.Length > 0) { FilePath = FileUp.meUpfile(this.File1, @"~\file\", true); FilePath = FilePath.Substring(FilePath.IndexOf('\\') + 1); } string title = this.txt_title.Text; if (title == null || title.Length <= 0) { JS.Alert("标题不能为空!"); return; } if (title.Length >= 255) { JS.Alert("标题过长!"); return; } string author = this.txt_author.Text; if (author.Length >= 255) { JS.Alert("作者名称过长!"); return; } string strDateTime = this.txt_DateTime.Value; string content = this.content2.Value; string type = UID == "news" ? "平台动态" : "标准规范"; string sql = "insert into t_news (ptitle,pcontent,puser,pdate,ptype,purl) values(@ptitle,@pcontent,@puser,@pdate,@ptype,@purl)"; ArrayList insertValue = new ArrayList(); OleDbParameter ptitle = new OleDbParameter("@ptitle", OleDbType.VarChar); ptitle.Value = title; insertValue.Add(ptitle); OleDbParameter pcontent = new OleDbParameter("@pcontent", OleDbType.LongVarWChar); pcontent.Value = content; insertValue.Add(pcontent); OleDbParameter puser = new OleDbParameter("@puser", OleDbType.VarChar); puser.Value = author; insertValue.Add(puser); OleDbParameter pdate = new OleDbParameter("@pdate", OleDbType.VarChar); pdate.Value = strDateTime; insertValue.Add(pdate); OleDbParameter ptype = new OleDbParameter("@ptype", OleDbType.VarChar); ptype.Value = type; insertValue.Add(ptype); OleDbParameter purl = new OleDbParameter("@purl", OleDbType.LongVarWChar); purl.Value = FilePath; insertValue.Add(purl); int p = AccessDb.ExecuteNon(sql, ref insertValue); JS.Alert("添加成功!"); this.txt_author.Text = ""; this.txt_title.Text = ""; this.content2.Value = ""; this.txt_DateTime.Value = DateTime.Now.ToUniversalTime().ToString(); }
//项目申报 protected void Button1_Click(object sender, EventArgs e) { if (Request.QueryString["type"] != null) { //添加 if (!FileUpload2.HasFile && string.IsNullOrEmpty(Label1.Text)) { Message("请上传详细材料", false); return; } //更新 int id = Convert.ToInt32(Request.QueryString["id"].ToString()); var Item = DB.ResearchItem.FirstOrDefault(a => a.Id == id);//获取对象 Item.ItemName = ItemName.Text; Item.ItemType = ItemType.Text; Item.ItemCompany = ItemCompany.Text; Item.MajorPerson = MajorPerson.Text; Item.Tel = Tel.Text; Item.Funds = Convert.ToDecimal(Funds.Text); Item.ExeYear = Convert.ToInt32(ExeYear.Text); if (FileUpload2.HasFile) { string fileName = string.Empty; Item.UpFile = FileUp.SaveFile(FileUpload2, Server.MapPath("~/UpFile/"), ref fileName); Item.FileName = fileName; } Item.State = "暂存"; //更新数据 DB.Entry(Item).State = EntityState.Modified; DB.SaveChanges(); } else { //添加 if (!FileUpload1.HasFile) { Message("请上传详细材料"); return; } ResearchItem Item = new ResearchItem(); Item.PersonId = Convert.ToInt32(Session["PersonId"]); Item.ItemName = ItemName.Text; Item.ItemType = ItemType.Text; Item.ItemCompany = ItemCompany.Text; Item.MajorPerson = MajorPerson.Text; Item.Tel = Tel.Text; Item.Funds = Convert.ToDecimal(Funds.Text); Item.ExeYear = Convert.ToInt32(ExeYear.Text); string fileName = string.Empty; Item.UpFile = FileUp.SaveFile(FileUpload1, Server.MapPath("~/UpFile/"), ref fileName); Item.FileName = fileName; Item.OperTime = DateTime.Now; Item.State = "暂存"; //插入数据 DB.ResearchItem.Add(Item); DB.SaveChanges(); //将自己作为参与人员 ItemPersonnel itemPerson = new ItemPersonnel(); itemPerson.ItemId = Item.Id; itemPerson.PersonId = Convert.ToInt32(Session["PersonId"]); itemPerson.OperTime = DateTime.Now; DB.ItemPersonnel.Add(itemPerson); DB.SaveChanges(); } Message("/ResearchItemPage/Manage.aspx", "保存成功"); }
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"); }