public FileResult ImageHandler(Guid?fileId) { var bo = new BLL.File(); var file = bo.FirstOrDefault(x => x.FileId == fileId); return(File(file.Context, file.ContextType, file.Title)); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string write = "ok"; DataTable dt = new BLL.File().GetDownloadList(context.Request.QueryString["fileid"]).Tables[0]; if (dt.Rows.Count > 0) { string fileName = dt.Rows[0]["name"].ToString(); string filePath = context.Server.MapPath(ConfigurationManager.AppSettings["FolderPath"] + dt.Rows[0]["path"].ToString()); if (System.IO.File.Exists(filePath)) { context.Session.Add("download", new string[] { fileName, filePath }); } else { write = "文件不存在。"; } } else { write = "文件不存在。"; } context.Response.Write(write); }
// // GET: /Home/ public ActionResult Index() { RoteValueHelper rvh = new RoteValueHelper(); var index = rvh.GetInt("index", 1); var pageSize = 10; var startIndex = (index - 1) * pageSize; var pageBll = new BLL.Page(); var pages = pageBll.GetPages(startIndex, 10); List<Photo.Web.Models.Page> list = null; if (pages != null) { var pageIds = pages.Select(o => o.id).AsEnumerable(); var fileBll = new BLL.File(); var files = fileBll.GetFileInfos(pageIds); var tagBll = new BLL.Tag(); var tags = tagBll.GetPageTags(pageIds); if (files != null) { var imgs = (from f in files select new Photo.Web.Models.Img { Id = f.id, Url = f.url, Path = f.path, PageId = f.PageId, Width = f.width, Height = f.height }).ToList(); list = (from p in pages select new Photo.Web.Models.Page { Id = p.id, AddTime = p.add_time, Title = p.title, Description = p.description, DefaultImg = imgs.FirstOrDefault(o => o.PageId == p.id), }).ToList(); list.ForEach(p => { p.Tags = (from t in tags where t.PageID == p.Id select new Web.Models.Tag { ID = t.id, Name = t.tag, Citations = t.citations }).ToList(); }); } } return View(list); }
private string Dels(HttpContext context) { string root = ConfigurationManager.AppSettings["FolderPath"]; string selectid = context.Request.Params["cbx_select"].Trim(); DataTable dt = new BLL.File().GetDeleteList(selectid).Tables[0]; string path = string.Empty; foreach (DataRow dr in dt.Rows) { path = context.Server.MapPath(root + "/" + dr[0].ToString()); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } } return(new BLL.File().DeleteList(selectid) ? "success" : ""); }
//public string CheckData(string ID,string up_per,string dowm_per) //{ // string data=""; // bool b = false; // bool b1 = false; // WCDataProvider db = new WCDataProvider(); // WCDataStoreProcedures dsp = new WCDataStoreProcedures("pro_folder", WCDataAction.Query9); // dsp.InputPars.Add("@folder_id", ID); // DataTable dt = new DataTable(); // if (db.Execute(dsp).ExecuteState) // { // dt = dsp.OutputDataSet.Tables[0]; // } // if (dt.Rows.Count > 0) // { // for (int i = 0; i < dt.Rows.Count; i++) // { // if (up_per.Length< dt.Rows[i]["up_permission"].ToString().Length) // { // b = true; // } // if (dowm_per.Length<dt.Rows[i]["dowm_permission"].ToString().Length) // { // b1 = true; // } // } // } // if (b) // { // data += "修改后该文件夹的上传权限小于它的子文件夹的上传权限\n,"; // } // if (b1) // { // data+="修改后该文件夹的下载权限小于它的子文件夹的下载权限\n,"; // } // return data; //} public string Del(HttpContext context) { string data = ""; string ftype = context.Request.Params["ftype"].Trim(); if (ftype == "1") { WCDataProvider db = new WCDataProvider(); WCDataStoreProcedures dsp = new WCDataStoreProcedures("pro_folder", WCDataAction.Query11); dsp.InputPars.Add("@folder_id", context.Request["ID"].ToString()); if (db.Execute(dsp).ExecuteState) { if (dsp.OutputPars["@Error"].ToString() == "" || string.IsNullOrEmpty(dsp.OutputPars["@Error"].ToString())) { data = "success"; string mainPath = ConfigurationManager.AppSettings["FolderPath"]; string Path = System.Web.HttpContext.Current.Server.MapPath(mainPath + dsp.OutputPars["@OutPath"].ToString()); if (Directory.Exists(Path)) { Directory.Delete(Path); } } else { data = dsp.OutputPars["@Error"].ToString() + "请将该文件夹下的子文件夹和文件删除,再进行该操作!"; } } else { data = "删除失败!"; } } else if (ftype == "2") { int fileid = int.Parse(context.Request["ID"].Substring(2)); string path = context.Server.MapPath(ConfigurationManager.AppSettings["FolderPath"] + "/" + context.Request["folder_path"]); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } data = new BLL.File().Delete(fileid) ? "success" : "删除失败"; } return(data); }
private string ReviewFile(HttpContext context) { try { HttpPostedFile hpfile = context.Request.Files["Filedata"]; string path = context.Server.MapPath(ConfigurationManager.AppSettings["FolderPath"] + "/" + context.Request.Form["folderpath"]); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string kzm = hpfile.FileName.Substring(hpfile.FileName.LastIndexOf('.')); string fileName = hpfile.FileName.Remove(hpfile.FileName.LastIndexOf('.')); string fn = string.Empty; for (int i = 0; System.IO.File.Exists(path + "/" + fileName + fn + kzm); i++) { fn = "(" + i + ")"; } fileName = fileName + fn + kzm; hpfile.SaveAs(path + "/" + fileName); Model.File file = new Model.File(); file.file_name = hpfile.FileName.Substring(0, hpfile.FileName.LastIndexOf('.')) + fn; file.type = hpfile.FileName.Substring(hpfile.FileName.LastIndexOf('.')); file.pwdflag = 0; file.up_person = Convert.ToInt32((context.Session["login"] as Model.BaseUser).UserID); file.up_date = DateTime.Now; file.cate_id = int.Parse(context.Request.Form["folderid"]); file.flieGuid = fileName; file.activate = 1; new BLL.File().Add(file); DataTable dt = new BLL.File().GetList(" flieGuid='" + fileName + "' ").Tables[0]; dt.Rows.Add(dt.NewRow()); return(dt.Rows[0]["ID"].ToString() + "|" + fileName); } catch (Exception ex) { return("Error: " + ex.Message); } }
// // GET: /Page/ public ActionResult Index() { RoteValueHelper rvh = new RoteValueHelper(); var pageId = rvh.GetInt("pageId", 1); var pageBll = new BLL.Page(); var tagBll = new BLL.Tag(); var fileBll = new BLL.File(); Models.Page page = null; try { var pageInfo = pageBll.GetPage(pageId); var tagInfos = tagBll.GetPageTags(pageId); var imgs = fileBll.GetFileInfos(pageId); page = new Models.Page { Title = pageInfo.title, AddTime = pageInfo.add_time }; page.Tags = (from t in tagInfos select new Models.Tag { ID = t.id, Name = t.tag }).ToList(); page.Imgs = (from i in imgs select new Models.Img { Id = i.id, Path = i.path }).ToList(); } catch (Exception ex) { } return View(page); }