The main need is to upload images and file management Service side of the transformation
public class Kindeditorcontroller:controller {private Ihostingenvironment hostingenv; ReadOnly string uploadfilepath = "Uploadfiles";//Save the root directory of the uploaded file public kindeditorcontroller (Ihostingenvironment hosting ENV) {this.hostingenv = hostingenv; } public Async task<iactionresult> savefiles (string dir) {if (request.form.files.c Ount () = = 0) {return showerror ("Please select the uploaded file"); } var file = Request.form.files[0];//kindeditor of the uploaded files control, one file at a time//define the file extension allowed to upload Hashtable exttable = new Hashtable (); Exttable.add ("image", "gif,jpg,jpeg,png,bmp"); Exttable.add ("Flash", "swf,flv"); Exttable.add ("Media", "SWF,FLV,MP3,WAV,WMA,WMV,MID,AVI,MPG,ASF,RM,RMVB"); Exttable.add ("File", "doc,docx,xls,xlsx,ppt,htm,html,txt,zip,rar,gz,bz2"); if (String.IsNullOrEmpty (dir)) {dir = "image"; } String fileext = path.getextension (file. FileName). ToLower (); if (String.IsNullOrEmpty (fileext) | | Array.indexof (((String) Exttable[dir]). Split (', '), fileext.substring (1). ToLower ()) = =-1) {return ShowError ("The upload file name extension is not allowed. \ n allows only "+ ((String) Exttable[dir]) +" format. "); } string physicalfilepath = Hostingenv.webrootpath; Create folder String Dirpath = Physicalfilepath + "\ \" + Uploadfilepath + "\ \" + dir + "\ \"; String webpath = "/" + Uploadfilepath + "/" + dir + "/"; if (! Directory.Exists (Dirpath)) {directory.createdirectory (Dirpath); } String Ymd = DateTime.Now.ToString ("YyyyMMdd", datetimeformatinfo.invariantinfo); Dirpath + = ymd + "\ \"; Webpath + = Ymd + "/"; if (! Directory.Exists (Dirpath)) {directory.createdirectory (Dirpath); } string SuiJishu =math.abs (Guid.NewGuid (). GetHashCode ()). ToString (); String NewFileName = DateTime.Now.ToString ("Yyyymmddhhmmss_" + Suijishu, Datetimeformatinfo.invariantinfo) + Fileext; String fileName = Dirpath + [email protected] "{newfilename}"; using (FileStream fs = System.IO.File.Create (FileName)) {await File. Copytoasync (FS); Fs. Flush (); } string fName = Webpath + newfilename; Hashtable hash = new Hashtable (); hash["error"] = 0; hash["url"] = FName; return Json (hash); } [Nonaction] Private Iactionresult showerror (String message) {Hashtable hash = new Hasht Able (); hash["Error"] = 1; hash["message"] = message; return Json (hash); } public Iactionresult FileManager () {String Rooturl = "/" +uploadfilepath+ "/"; Picture Extension String fiLetypes = "Gif,jpg,jpeg,png,bmp"; String Currentpath = ""; String Currenturl = ""; String Currentdirpath = ""; String Moveupdirpath = ""; String Dirpath = hostingenv.webrootpath + "\ \" + Uploadfilepath + "\ \"; String dirName = request.query["dir"]; if (! String.IsNullOrEmpty (DirName)) {if (Array.indexof ("Image,flash,media,file"). Split (', '), dirName) = =-1) {return ShowError ("directory Error"); } Dirpath + = DirName + "/"; Rooturl + = DirName + "/"; if (! Directory.Exists (Dirpath)) {directory.createdirectory (Dirpath); }}//Set each path and URL according to the path parameter String path = request.query["path"]; Path = string.isnullorempty (path)? "": path; if (Path = = "") {Currentpath = Dirpath; Currenturl = Rooturl; Currentdirpath = ""; Moveupdirpath = ""; } else {Currentpath = Dirpath + path; Currenturl = rooturl + path; Currentdirpath = path; Moveupdirpath = Regex.Replace (Currentdirpath, @ "(. *?) [^\/]+\/$ "," $ "); }//Sort form, name or size or type String order = request.query["Order"]; Order = String.IsNullOrEmpty (order)? "": Order. ToLower (); Not allowed to use: Move to the previous-level directory if (Regex.IsMatch (Path, @ "\.\.")) {return ShowError ("Access is not allowed."); }//The last character is not/if (path! = "" &&!path. EndsWith ("/")) {return ShowError ("Parameter is not valid."); }//directory does not exist or is not a directory if (! Directory.Exists (Currentpath)) {return ShowError ("Directory does not exist."); }//Traverse directory to get file information string[] dirlist = directory.getdirectories (Currentpath); string[] fileList = Directory.GetFiles (Currentpath); Switch (order) {case "size": Array.Sort (Dirlist, New Namesorter ()); Array.Sort (FileList, New Sizesorter ()); Break Case "type": Array.Sort (Dirlist, New Namesorter ()); Array.Sort (FileList, New Typesorter ()); Break Case "name": Default:Array.Sort (Dirlist, New Namesorter ()); Array.Sort (FileList, New Namesorter ()); Break } Hashtable result = new Hashtable (); result["Moveup_dir_path"] = Moveupdirpath; result["Current_dir_path"] = Currentdirpath; result["Current_url"] = Currenturl; result["Total_count"] = DirlisT.length + filelist.length; listPage
<script> kindeditor.ready (function (K) { window.editor = k.create (' #editor_id ', { Uploadjson: ' @ Url.action ("SaveFiles", "kindeditor") ', Filemanagerjson: ' @Url. Action ("FileManager", "kindeditor") ', Allowfilemanager:true }) ; </script>
Use of kindeditor in ASP. NET Core