public ActionResult TeaUpStuChu() { string p = Server.MapPath(""); StuFileService adfs = new StuFileService(); StuFileDal adfd = new StuFileDal(); StuFile adf = new StuFile(); string name = Request["name"]; StudentDal stud = new StudentDal(); Student stu = new Student(); IQueryable <Student> siq = stud.GetEntities(U => U.Stu_Name == name); foreach (var item in siq) { stu = item; } var file = Request.Files["file2"]; if (file.ContentLength == 0) { return(Content("请选择要上传的文件")); } var intro = Request["intro2"]; var filename = Request["filename2"]; IQueryable <StuFile> iq = adfd.GetEntities(u => u.Student.Stu_Name == name && u.Status == 1); if (iq.Count() == 0) { return(Content("改还未提交过论文初稿")); } foreach (var item in iq) { adf = item; } string s = file.FileName; //全路径的名字 int index = s.LastIndexOf("."); //获取最后面点的位置 string hzm = s.Substring(index); // 获取后缀名 try { System.IO.File.Delete(p + "/" + stu.Department.Dep_Name + "/论文初稿/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文初稿" + hzm); } catch (Exception) { } string path = "/Upload/管理与信息工程学院/论文初稿/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文初稿" + hzm;; //防止命名相同 adfs.UpdateStuFile(adf, filename, intro, path, 4); file.SaveAs(Request.MapPath(path)); return(Content("上传成功")); }
public ActionResult StuFileOverUpLoad() { string p = Server.MapPath(""); //System.IO.File.Delete(p + "/管理与信息工程学院/论文终稿/201301020127-黄杰-论文终稿.jpg"); //StuFileService adfs = new StuFileService(); //StuFileDal adfd = new StuFileDal(); //Student stu = (Student)Session["student"]; //var file = Request.Files["file1"]; //if (file.ContentLength==0) //{ // return Content("请选择要上传的文件"); //} //var filename = Request["filename1"]; //var intro = Request["intro1"]; //IQueryable<StuFile> iq = adfd.GetEntities(u => u.Student.Stu_Id == stu.Stu_Id&&u.Status==1); //if (iq.Count()==0) //{ // return Content("你还未提交过论文"); //} //StuFile adf = new StuFile(); //foreach (var item in iq) //{ // adf = item; //} //string s = file.FileName; //全路径的名字 //int index = s.LastIndexOf("."); //获取最后面点的位置 //string hzm = s.Substring(index); // 获取后缀名 //string path = "/Upload/" +filename+ Guid.NewGuid().ToString() + hzm; //防止命名相同 //adfs.UpdateStuFile(adf,filename,intro,path); //file.SaveAs(Request.MapPath(path)); //return Content("上传成功"); var file = Request.Files["file1"]; if (file.ContentLength == 0) { return(Content("请选择要上传的文件")); } var intro = Request["intro1"]; var filename = Request["filename1"]; StuFileService adfs = new StuFileService(); StuFileDal adfd = new StuFileDal(); Student stu = (Student)Session["student"]; var filename1 = stu.Stu_Num + "-" + stu.Stu_Name + "-" + "开题报告"; string filestyle = Request["style"]; string dir = stu.Department.Dep_Name; StuFile adf = new StuFile(); if (filestyle == "开题报告") { IQueryable <StuFile> iq = adfd.GetEntities(u => u.Student.Stu_Id == stu.Stu_Id && u.Status == 0); if (iq.Count() == 0) { return(Content("你还未提交过开题报告")); } foreach (var item in iq) { adf = item; } string s = file.FileName; //全路径的名字 int index = s.LastIndexOf("."); //获取最后面点的位置 string hzm = s.Substring(index); // 获取后缀名 try { System.IO.File.Delete(p + "/" + stu.Department.Dep_Name + "/开题报告/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "开题报告" + hzm); } catch (Exception) { } string path = "/Upload/" + dir + "/" + filestyle + "/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "开题报告" + hzm; //防止命名相同 adfs.UpdateStuFile(adf, filename1, intro, path, 0); file.SaveAs(Request.MapPath(path)); return(Content("上传成功")); } if (filestyle == "论文初稿") { IQueryable <StuFile> iq = adfd.GetEntities(u => u.Student.Stu_Id == stu.Stu_Id && u.Status == 1); if (iq.Count() == 0) { return(Content("你还未提交过论文初稿")); } foreach (var item in iq) { adf = item; } string s = file.FileName; //全路径的名字 int index = s.LastIndexOf("."); //获取最后面点的位置 string hzm = s.Substring(index); // 获取后缀名 try { System.IO.File.Delete(p + "/" + stu.Department.Dep_Name + "/论文初稿/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文初稿" + hzm); } catch (Exception) { } string path = "/Upload/" + dir + "/" + filestyle + "/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文初稿" + hzm; //防止命名相同 adfs.UpdateStuFile(adf, filename, intro, path, 1); file.SaveAs(Request.MapPath(path)); return(Content("上传成功")); } if (filestyle == "论文终稿") { IQueryable <StuFile> iq = adfd.GetEntities(u => u.Student.Stu_Id == stu.Stu_Id && u.Status == 2); if (iq.Count() == 0) { return(Content("你还未提交过论文终稿")); } foreach (var item in iq) { adf = item; } string s = file.FileName; //全路径的名字 int index = s.LastIndexOf("."); //获取最后面点的位置 string hzm = s.Substring(index); // 获取后缀名 try { System.IO.File.Delete(p + "/" + stu.Department.Dep_Name + "/论文终稿/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文终稿" + hzm); } catch (Exception) { } string path = "/Upload/" + dir + "/" + filestyle + "/" + stu.Stu_Num + "-" + stu.Stu_Name + "-" + "论文终稿" + hzm; //防止命名相同 adfs.UpdateStuFile(adf, filename, intro, path, 2); file.SaveAs(Request.MapPath(path)); return(Content("上传成功")); } return(null); }