KindEditor編輯器在ASP.NET中的使用
最近做的項目中都有用到富文本編輯器,一直在尋找最后用的富文本編輯器,之前用過CKEditor,也用過UEditor,這次打算用 一下KindEditor。
KindEditor簡介:
KindEditor是一套開源的HTML可視化編輯器,主要用于讓用戶在網站上獲得所見即所得編輯效果,兼容IE、Firefox、Chrome、Safari、Opera等主流瀏覽器。KindEditor使用javaScript編寫,可以無縫的于Java、.NET、php、ASP等程序接合。 KindEditor非常適合在CMS、商城、論壇、博客、Wiki、電子郵件等互聯網應用上使用,2006年7月首次發布2.0以來,KindEditor依靠出色的用戶體驗和領先的技術不斷擴大編輯器市場占有率,目前在國內已經成為最受歡迎的編輯器之一。[來自百度百科]
官網簡介、 官網下載 、官方文檔 、官網Demo演示
KindEditor使用:
將下載的開發包中不需要的刪掉,只保留項目需要的文件,我的項目是ASP.NET項目,所引用的開發包資源如下圖所示
html設置:
js初始化:
獲取編輯器的值:
var html = editor.html();
editor.sync();
//原生js獲取
var html = document.getElementById("editor").value;
//jquery獲取
var html =$("#editor").val();
//KindEditor 方式
var html = K('#editor').val();
設置編輯器的值:
editor.html('html內容');
上傳文件處理程序:
參考所給的示例,只是對示例加以驗證,驗證是否有上傳權限
上傳文件列表處理程序:
獲取上傳文件列表同樣的,首先進行權限驗證:
1 public class UploadFileHandler : IHttpHandler, IRequiressessionState 2 { 3 PRivate static HttpResponse Response = null; 4 //最大文件大小 5 const int MAXFILESIZE = 10240*1024; 6 7 public void ProcessRequest(HttpContext context) 8 { 9 //驗證上傳權限 10 if (context.Session["User"] == null) 11 { 12 context.Response.Write("no permission"); 13 context.Response.End(); 14 return; 15 } 16 Response = context.Response; 17 string flag = context.Request["customUpload"]; 18 //從配置文件中獲取網站首頁路徑 19 String aspxUrl = Common.ConfigurationHelper.AppSetting("HomeUrlInfo"); 20 //文件保存目錄路徑 21 System.Text.StringBuilder savePath = new System.Text.StringBuilder("/Upload/"); 22 try 23 { 24 //定義允許上傳的文件擴展名 25 Hashtable extTable = new Hashtable(); 26 extTable.Add("image", "jpg,jpeg,png,bmp"); 27 extTable.Add("Flash", "swf,flv"); 28 extTable.Add("media", "swf,flv,mp3,wav,wma,wmv,mid,avi,mpg,asf,rm,rmvb"); 29 extTable.Add("file", "doc,docx,xls,xlsx,UploadFileHandler Code1 using System; 2 using System.Collections; 3 using System.Collections.Generic; 4 using System.IO; 5 using System.Text.RegularExpressions; 6 using System.Web; 7 using System.Web.SessionState; 8 9 namespace Webapplication1.Admin 10 { 11 public class FileManagerHandler : IHttpHandler,IRequiresSessionState 12 { 13 public void ProcessRequest(HttpContext context) 14 { 15 //驗證權限 16 if (context.Session["User"] == null) 17 { 18 context.Response.Write("no permission"); 19 context.Response.End(); 20 return; 21 } 22 //從配置文件中讀取網址信息 23 String aspxUrl = Common.Config
新聞熱點
疑難解答