public void Add() { var file = Constant.Request.Files[0]; string path = Constant.Request["currentpath"]; var parant = -1; if (path.IsNotNullOrEmpty()) { parant = Convert.ToInt32(path); } if (parant == -1) { path = "~/client/" + RoolFolder; } else { path = "~/client/" + _fileServices.GetFolderById(parant).Url; } var count = _fileServices.GetFileByName(Folder, file.FileName).Count(); var name = file.FileName; if (count > 0) { name = name + "(" + (count + 1) + ")"; } var saveUrl = Constant.Server.MapPath(path) + "\\" + name; file.SaveAs(saveUrl); var mFile = new MFile(); mFile.Url = path + "\\" + name; mFile.Name = name; mFile.Createtime = DateTime.UtcNow; mFile.Updatetime = DateTime.UtcNow; mFile.Folder = parant; mFile.User = User; mFile.Role = GetRole(); mFile.FileType = Path.GetExtension(name).Replace(".", "").ToLower(); var info = new FileInfo(saveUrl); mFile.Size = info.Length; _fileServices.AddFile(mFile); var response = new FileManageResponse() { Error = "No error", Name = Path.GetFileName(name), Path = parant.ToString() }.SerializeObject(); Constant.Response.ContentType = "text/html"; Constant.Response.ContentEncoding = Encoding.UTF8; System.Web.UI.WebControls.TextBox txt = new System.Web.UI.WebControls.TextBox(); txt.TextMode = System.Web.UI.WebControls.TextBoxMode.MultiLine; txt.Text = response; StringWriter sw = new StringWriter(); System.Web.UI.HtmlTextWriter writer = new System.Web.UI.HtmlTextWriter(sw); txt.RenderControl(writer); Constant.Response.Write(sw.ToString() ); }
public void ProcessRequest(HttpContext context) { //if (!Roles.IsUserInRole("admin")) //{ // throw new HttpException(403, "forbidden"); //} context.Response.ClearHeaders(); context.Response.ClearContent(); context.Response.Clear(); switch (context.Request["mode"]) { case "getinfo": context.Response.ContentType = "plain/text"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Write(GetInfo(context.Request["path"])); break; case "getfolder": context.Response.ContentType = "plain/text"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Write(GetFolderInfo(context.Request["path"])); break; case "rename": context.Response.ContentType = "plain/text"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Write(Rename(context.Request["old"], context.Request["new"])); break; case "delete": context.Response.ContentType = "plain/text"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Write(Delete(context.Request["path"])); break; case "addfolder": context.Response.ContentType = "plain/text"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Write(AddFolder(context.Request["path"], context.Request["name"])); break; case "download": var fi = new FileInfo(context.Server.MapPath(context.Request["path"])); context.Response.AddHeader("Content-Disposition", "attachment; filename=" + context.Server.UrlPathEncode(fi.Name)); context.Response.AddHeader("Content-Length", fi.Length.ToString(CultureInfo.InvariantCulture)); context.Response.ContentType = "application/octet-stream"; context.Response.TransmitFile(fi.FullName); break; case "add": var file = context.Request.Files[0]; var path = context.Request["currentpath"]; Debug.Assert(file.FileName != null); var fn = Path.GetFileName(file.FileName); Debug.Assert(fn != null); file.SaveAs(context.Server.MapPath(Path.Combine(path, fn))); context.Response.ContentType = "text/html"; context.Response.ContentEncoding = Encoding.UTF8; var sb = new StringBuilder(); sb.AppendLine("{"); sb.AppendLine("\"Path\": \"" + path + "\","); sb.AppendLine("\"Name\": \"" + Path.GetFileName(file.FileName) + "\","); sb.AppendLine("\"Error\": \"No error\","); sb.AppendLine("\"Code\": 0"); sb.AppendLine("}"); var txt = new System.Web.UI.WebControls.TextBox { TextMode = System.Web.UI.WebControls.TextBoxMode.MultiLine, Text = sb.ToString() }; var sw = new StringWriter(); var writer = new System.Web.UI.HtmlTextWriter(sw); txt.RenderControl(writer); context.Response.Write(sw.ToString()); break; } }
public void ProcessRequest(HttpContext context) { context.Response.ClearHeaders(); context.Response.ClearContent(); context.Response.Clear(); switch (context.Request["mode"]) { case "getinfo": context.Response.ContentType = "plain/text"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Write(getInfo(context.Request["path"])); break; case "getfolder": context.Response.ContentType = "plain/text"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Write(getFolderInfo(context.Request["path"])); break; case "rename": context.Response.ContentType = "plain/text"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Write(Rename(context.Request["old"], context.Request["new"])); break; case "delete": context.Response.ContentType = "plain/text"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Write(Delete(context.Request["path"])); break; case "addfolder": context.Response.ContentType = "plain/text"; context.Response.ContentEncoding = Encoding.UTF8; context.Response.Write(AddFolder(context.Request["path"], context.Request["name"])); break; case "download": FileInfo fi = new FileInfo(context.Server.MapPath(context.Request["path"])); context.Response.AddHeader("Content-Disposition", "attachment; filename=" + context.Server.UrlPathEncode(context.Request["path"])); context.Response.AddHeader("Content-Length", fi.Length.ToString()); context.Response.ContentType = "application/octet-stream"; context.Response.TransmitFile(fi.FullName); break; case "add": System.Web.HttpPostedFile file = context.Request.Files[0]; string path = context.Request["currentpath"]; file.SaveAs(context.Server.MapPath(Path.Combine(path, Path.GetFileName(file.FileName)))); context.Response.ContentType = "text/html"; context.Response.ContentEncoding = Encoding.UTF8; StringBuilder sb = new StringBuilder(); sb.AppendLine("{"); sb.AppendLine("\"Path\": \"" + path + "\","); sb.AppendLine("\"Name\": \"" + Path.GetFileName(file.FileName) + "\","); sb.AppendLine("\"Error\": \"No error\","); sb.AppendLine("\"Code\": 0"); sb.AppendLine("}"); System.Web.UI.WebControls.TextBox txt = new System.Web.UI.WebControls.TextBox(); txt.TextMode = System.Web.UI.WebControls.TextBoxMode.MultiLine; txt.Text = sb.ToString(); StringWriter sw = new StringWriter(); System.Web.UI.HtmlTextWriter writer = new System.Web.UI.HtmlTextWriter(sw); txt.RenderControl(writer); context.Response.Write(sw.ToString()); break; default: break; } }