CKEditor和CKFinder在ASP.NET项目中安装,配置和使用详解
来源:互联网 发布:新疆教师网络培训网 编辑:程序博客网 时间:2024/05/21 16:23
一、概述
在CSDN潜水快两年了,之前都只是在上面寻找所需答案或者看一些相关的新闻。在这上面,的确可以找到很多你想要的东西,同是还可以学习和了解一些较新的软件使用文档和科技发展的一些新方向。一想到大学快毕业了,而自己却没有做出些什么贡献的事情来,心里不时的感觉有点懊悔之意。因此也想到在CSDN上写一些平时在学习和编程时的一些理解和总结,希望能够在这个平台上和广大的趣味相投的朋友一起共学习,共进步。有什么写得不好和不恰之处,还望各位读者指出纠正,我会倍加感谢。另外,除此之意,也有一些自己私人的想法,我也可以通过这种方式,记录我平时所学到的一些东西并通过文字保留下来,供以后查阅之用。好啦,接下来就是我要写的重点内容了
今天,我要介绍的是之前在项目中用到的一个很强大的在线网页编辑器————FCKEditor,既CKEditor。FCKeditor是一个专门使用在网页上属于开放源代码的所见即所得文字编辑器,其名称中的“FCK”是这个编辑器的作者的名字Frederico Caldeira Knabben的缩写。在09年发布更新到3.0后,改名为CKEditor,CK意指"Content and Knowledge"。CKEditor志于轻量化,不需要太复杂的安装步骤即可使用。它可和PHP、JavaScript、ASP、ASP.NET、ColdFusion、Java、以及ABAP等不同的编程语言相结合。在此,我主要介绍他在ASP.NET的安装,配置及使用。
一般,CKEditor是和CKFinder一起使用,CKFinder是一个强大而易于使用的Web浏览器Ajax文件管理器。其界面简单直观,文件安全上传和快速反应受到广大网络编程者的青睐。我们先从CKEditor和CKFinder的官方网站下载文件压缩包。地址:
CKEditor:http://ckeditor.com/download
CKFinder:http://cksource.com/ckfinder/download
因为我今天讲的是这两个编辑器在ASP.NET的应用,因此只需下载用于ASP.NET的压缩包,我下载的版本分别是ckeditor_aspnet_3.6.4和ckfinder_aspnet_2.4。
二、安装步骤
1.将CKEditor和CKFinder减压出来,把ckeditor_aspnet_3.6.4/_Samples/ckeditor目录下的ckeditor文件夹拷在WEB的根目录下,同样,将ckfinder_aspnet_2.4目录下的ckfinder拷在WEB的根目录下。CKFinder目录里的_samples和_source文件夹可以删除,其主要是CKFinder的源代码和演示文档,项目中用不到。
2.把ckeditor_aspnet_3.6.4/bin/Release目录下的CKEditor.NET.dll和ckfinder_aspnet_2.4\ckfinder\bin\Release目录下的CKFinder.dll拷贝在项目下放DLL文件的文件夹里,一般是在bin目录下。然后右键点击“引用“,添加引用,在浏览选项卡下点击浏览,找到那两个DLL文件,将其添加进来。
3.在工具箱常规选项卡上右键,选择”选择项“,在.NET Framework选项卡中点击浏览,把CKEditor.NET.dll选择,确定,这样在常规选项卡里就可以看见多出个CKEditorControl控件。
4.在页面<head>中引入ckeditor核心文件ckeditor.js,并将CKEditorControl控件拖在页面中。这时就可以看到在浏览器中看到ckeditor编辑器。
<script src="ckeditor/ckeditor.js" type="text/javascript"></script>三、配置编辑器
1.ckeditor的配置都集中在 ckeditor/config.js文件中,当然,你也可以直接在控件的属性栏中更改和配置相应的属性。下面是一些常用的配置参数:
// 界面语言,默认为 'en' config.language = 'zh-cn'; // 设置宽高 config.width = 400; config.height = 400; // 编辑器样式,有三种:'kama'(默认)、'office2003'、'v2' config.skin = 'v2'; // 背景颜色 config.uiColor = '#FFF'; //工具栏(基础'Basic'、全能'Full'、自定义)plugins/toolbar/plugin.js config.toolbar = 'Basic'; config.toolbar = 'Full'; 这将配合: config.toolbar_Full = [ ['Source','-','Save','NewPage','Preview','-','Templates'], ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print','SpellChecker', 'Scayt'], ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select','Button', 'ImageButton', 'HiddenField'], '/', ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['Link','Unlink','Anchor'], ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'], '/', ['Styles','Format','Font','FontSize'], ['TextColor','BGColor'] ]; //工具栏是否可以被收缩 config.toolbarCanCollapse = true; //工具栏的位置 config.toolbarLocation ='top';//可选:bottom //工具栏默认是否展开 config.toolbarStartupExpanded = true; // 取消 “拖拽以改变尺寸”功能 plugins/resize/plugin.js config.resize_enabled = false; //改变大小的最大高度 config.resize_maxHeight = 3000; //改变大小的最大宽度 config.resize_maxWidth =3000; //改变大小的最小高度 config.resize_minHeight =250; //改变大小的最小宽度 config.resize_minWidth =750; // 当提交包含有此编辑器的表单时,是否自动更新元素内的数据 config.autoUpdateElement =true; // 设置是使用绝对目录还是相对目录,为空为相对目录 config.baseHref = '' // 编辑器的z-index值 config.baseFloatZIndex = 10000; //设置快捷键 config.keystrokes = [ [CKEDITOR.ALT + 121 /*F10*/, 'toolbarFocus' ], //获取焦点 [CKEDITOR.ALT + 122 /*F11*/, 'elementsPathFocus' ], //元素焦点 [ CKEDITOR.SHIFT + 121 /*F10*/,'contextMenu' ], //文本菜单 [ CKEDITOR.CTRL + 90 /*Z*/, 'undo' ], //撤销 [ CKEDITOR.CTRL + 89 /*Y*/, 'redo' ], //重做 [CKEDITOR.CTRL + CKEDITOR.SHIFT + 90 /*Z*/, 'redo' ], // [ CKEDITOR.CTRL + 76 /*L*/, 'link' ], //链接 [ CKEDITOR.CTRL + 66 /*B*/, 'bold' ], //粗体 [ CKEDITOR.CTRL + 73 /*I*/, 'italic' ], //斜体 [ CKEDITOR.CTRL + 85 /*U*/, 'underline' ], //下划线 [ CKEDITOR.ALT + 109 /*-*/,'toolbarCollapse' ] ] //设置快捷键 可能与浏览器快捷键冲突plugins/keystrokes/plugin.js. config.blockedKeystrokes = [ CKEDITOR.CTRL + 66 /*B*/, CKEDITOR.CTRL + 73 /*I*/, CKEDITOR.CTRL + 85 /*U*/ ] //设置编辑内元素的背景色的取值plugins/colorbutton/plugin.js. config.colorButton_backStyle = { element : 'span', styles : { 'background-color' : '#(color)'} } //设置前景色的取值 plugins/colorbutton/plugin.js config.colorButton_colors = '000,800000,8B4513,2F4F4F,008080,000080,4B0082,696969,B22222,A52A2A,DAA520, 006400,40E0D0,0000CD,800080,808080,F00,FF8C00,FFD700,008000,0FF,00F,EE82EE, A9A9A9,FFA07A,FFA500,FFFF00,00FF00,AFEEEE,ADD8E6,DDA0DD,D3D3D3,FFF0F5, FAEBD7,FFFFE0,F0FFF0,F0FFFF,F0F8FF,E6E6FA,FFF’ //是否在选择颜色时显示“其它颜色”选项plugins/colorbutton/plugin.js config.colorButton_enableMore =false //区块的前景色默认值设置 plugins/colorbutton/plugin.js config.colorButton_foreStyle = { element : 'span', styles : { 'color' : '#(color)' } }; //所需要添加的CSS文件 在此添加 可使用相对路径和网站的绝对路径 config.contentsCss = './contents.css'; //文字方向 config.contentsLangDirection ='rtl'; //从左到右 //CKeditor的配置文件 若不想配置 留空即可 CKEDITOR.replace( 'myfiled', { customConfig : './config.js' } ); //界面编辑框的背景色 plugins/dialog/plugin.js config.dialog_backgroundCoverColor = '#fffefd'; //可设置参考 config.dialog_backgroundCoverColor = 'white' //默认 //背景的不透明度 数值应该在:0.0~1.0 之间plugins/dialog/plugin.js config.dialog_backgroundCoverOpacity =0.5 //移动或者改变元素时 边框的吸附距离 单位:像素plugins/dialog/plugin.js config.dialog_magnetDistance = 20; //是否拒绝本地拼写检查和提示 默认为拒绝 目前仅firefox和safari支持plugins/wysiwygarea/plugin.js. config.disableNativeSpellChecker =true //进行表格编辑功能 如:添加行或列 目前仅firefox支持plugins/wysiwygarea/plugin.js config.disableNativeTableHandles =true; //默认为不开启 //是否开启 图片和表格 的改变大小的功能config.disableObjectResizing = true; config.disableObjectResizing= false //默认为开启 //设置HTML文档类型 config.docType ='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd%22' ; //是否对编辑区域进行渲染plugins/editingblock/plugin.js config.editingBlock = true; //编辑器中回车产生的标签 config.enterMode =CKEDITOR.ENTER_P; //可选:CKEDITOR.ENTER_BR或CKEDITOR.ENTER_DIV //是否使用HTML实体进行输出 plugins/entities/plugin.js config.entities = true; //定义更多的实体 plugins/entities/plugin.js config.entities_additional = '#39'; //其中#代替了& //是否转换一些难以显示的字符为相应的HTML字符plugins/entities/plugin.js config.entities_greek = true; //是否转换一些拉丁字符为HTMLplugins/entities/plugin.js config.entities_latin = true; //是否转换一些特殊字符为ASCII字符 如"This is Chinese:汉语."转换为"This is Chinese: 汉语."plugins/entities/plugin.js config.entities_processNumerical =false; //添加新组件 config.extraPlugins ='myplugin'; //非默认 仅示例 //使用搜索时的高亮色 plugins/find/plugin.js config.find_highlight = { element : 'span', styles: { 'background-color' : '#ff0', 'color' : '#00f' } }; //默认的字体名 plugins/font/plugin.js config.font_defaultLabel = 'Arial'; //字体编辑时的字符集 可以添加常用的中文字符:宋体、楷体、黑体等plugins/font/plugin.js config.font_names = 'Arial;Times NewRoman;Verdana'; //文字的默认式样 plugins/font/plugin.js config.font_style = { element : 'span', styles : { 'font-family' : '#(family)' }, overrides : [ { element :'font', attributes : { 'face' : null } } ] }; //字体默认大小 plugins/font/plugin.js config.fontSize_defaultLabel = '12px'; //字体编辑时可选的字体大小 plugins/font/plugin.js config.fontSize_sizes='8/8px;9/9px;10/10px;11/11px;12/12px;14/14px;16/16px;18/18px;20/20px;22/22px;24/24px;26/26px;28/28px;36/36px;48/48px;72/72px' //设置字体大小时 使用的式样 plugins/font/plugin.js config.fontSize_style = { element : 'span', styles : { 'font-size' : '#(size)' }, overrides : [ {element : 'font', attributes : { 'size' : null } } ] }; //是否强制复制来的内容去除格式plugins/pastetext/plugin.js config.forcePasteAsPlainText =false//不去除 //是否强制用“&”来代替“&”plugins/htmldataprocessor/plugin.js config.forceSimpleAmpersand = false; //对address标签进行格式化 plugins/format/plugin.js config.format_address = { element : 'address', attributes : { class :'styledAddress' } }; //对DIV标签自动进行格式化 plugins/format/plugin.js config.format_div = { element : 'div', attributes : { class :'normalDiv' } }; //对H1标签自动进行格式化 plugins/format/plugin.js config.format_h1 = { element : 'h1', attributes : { class :'contentTitle1' } }; //对H2标签自动进行格式化 plugins/format/plugin.js config.format_h2 = { element : 'h2', attributes : { class :'contentTitle2' } }; //对H3标签自动进行格式化 plugins/format/plugin.js config.format_h1 = { element : 'h3', attributes : { class :'contentTitle3' } }; //对H4标签自动进行格式化 plugins/format/plugin.js config.format_h1 = { element : 'h4', attributes : { class :'contentTitle4' } }; //对H5标签自动进行格式化 plugins/format/plugin.js config.format_h1 = { element : 'h5', attributes : { class :'contentTitle5' } }; //对H6标签自动进行格式化 plugins/format/plugin.js config.format_h1 = { element : 'h6', attributes : { class :'contentTitle6' } }; //对P标签自动进行格式化 plugins/format/plugin.js config.format_p = { element : 'p', attributes : { class : 'normalPara' }}; //对PRE标签自动进行格式化 plugins/format/plugin.js config.format_pre = { element : 'pre', attributes : { class : 'code'} }; //用分号分隔的标签名字 在工具栏上显示plugins/format/plugin.js config.format_tags ='p;h1;h2;h3;h4;h5;h6;pre;address;div'; //是否使用完整的html编辑模式如使用,其源码将包含:<html><body></body></html>等标签 config.fullPage = false; //是否忽略段落中的空字符 若不忽略 则字符将以“”表示plugins/wysiwygarea/plugin.js config.ignoreEmptyParagraph = true; //在清除图片属性框中的链接属性时 是否同时清除两边的<a>标签plugins/image/plugin.js config.image_removeLinkByEmptyURL = true; //一组用逗号分隔的标签名称,显示在左下角的层次嵌套中plugins/menu/plugin.js. config.menu_groups='clipboard,form,tablecell,tablecellproperties,tablerow,tablecolumn,table,anchor,link,image,flash,checkbox,radio,textfield,hiddenfield,imagebutton,button,select,textarea'; //显示子菜单时的延迟,单位:ms plugins/menu/plugin.js config.menu_subMenuDelay = 400; //当执行“新建”命令时,编辑器中的内容plugins/newpage/plugin.js config.newpage_html = ''; //当从word里复制文字进来时,是否进行文字的格式化去除plugins/pastefromword/plugin.js config.pasteFromWordIgnoreFontFace = true; //默认为忽略格式 //是否使用<h1><h2>等标签修饰或者代替从word文档中粘贴过来的内容plugins/pastefromword/plugin.js config.pasteFromWordKeepsStructure = false; //从word中粘贴内容时是否移除格式plugins/pastefromword/plugin.js config.pasteFromWordRemoveStyle =false; //对应后台语言的类型来对输出的HTML内容进行格式化,默认为空 config.protectedSource.push( /<"?["s"S]*?"?>/g ); // PHP Code config.protectedSource.push( //g ); // ASP Code config.protectedSource.push(/(]+>["s|"S]*?<"/asp:[^">]+>)|(]+"/>)/gi ); // ASP.NetCode //当输入:shift+Enter时插入的标签 config.shiftEnterMode = CKEDITOR.ENTER_P; //可选:CKEDITOR.ENTER_BR或CKEDITOR.ENTER_DIV //可选的表情替代字符 plugins/smiley/plugin.js. config.smiley_descriptions = [ ':)', ':(', ';)', ':D', ':/',':P', '', '', '', '', '', '', '', ';(', '', '','', '', '', ':kiss', '' ]; //对应的表情图片 plugins/smiley/plugin.js config.smiley_images = [ 'regular_smile.gif','sad_smile.gif','wink_smile.gif','teeth_smile.gif','confused_smile.gif','tounge_smile.gif', 'embaressed_smile.gif','omg_smile.gif','whatchutalkingabout_smile.gif','angry_smile.gif','angel_smile.gif','shades_smile.gif', 'devil_smile.gif','cry_smile.gif','lightbulb.gif','thumbs_down.gif','thumbs_up.gif','heart.gif', 'broken_heart.gif','kiss.gif','envelope.gif']; //表情的地址 plugins/smiley/plugin.js config.smiley_path = 'plugins/smiley/images/'; //页面载入时,编辑框是否立即获得焦点plugins/editingblock/plugin.js plugins/editingblock/plugin.js. config.startupFocus = false; //载入时,以何种方式编辑 源码和所见即所得 "source"和"wysiwyg"plugins/editingblock/plugin.js. config.startupMode ='wysiwyg'; //载入时,是否显示框体的边框plugins/showblocks/plugin.js config.startupOutlineBlocks = false; //是否载入样式文件 plugins/stylescombo/plugin.js. config.stylesCombo_stylesSet = 'default'; //以下为可选 config.stylesCombo_stylesSet = 'mystyles'; config.stylesCombo_stylesSet = 'mystyles:/editorstyles/styles.js'; config.stylesCombo_stylesSet ='mystyles:http://www.example.com/editorstyles/styles.js'; //起始的索引值 config.tabIndex = 0; //当用户键入TAB时,编辑器走过的空格数,( )当值为0时,焦点将移出编辑框 plugins/tab/plugin.js config.tabSpaces = 0; //默认使用的模板 plugins/templates/plugin.js. config.templates = 'default'; //用逗号分隔的模板文件plugins/templates/plugin.js. config.templates_files = [ 'plugins/templates/templates/default.js' ] //当使用模板时,“编辑内容将被替换”框是否选中plugins/templates/plugin.js config.templates_replaceContent =true; //主题 config.theme = 'default'; //撤销的记录步数 plugins/undo/plugin.js config.undoStackSize =20; // 在 CKEditor 中集成 CKFinder,注意 ckfinder的路径选择要正确。 //CKFinder.SetupCKEditor(null, '/ckfinder/');
2.ckeditor要使用ckfinder时,必须配置以下参数:
config.filebrowserBrowseUrl = '/ckfinder/ckfinder.html'; //上传文件时浏览服务文件夹 config.filebrowserImageBrowseUrl = '/ckfinder/ckfinder.html?Type=Images'; //上传图片时浏览服务文件夹 config.filebrowserFlashBrowseUrl = '/ckfinder/ckfinder.html?Type=Flash'; //上传Flash时浏览服务文件夹 config.filebrowserUploadUrl = '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files'; //上传文件按钮(标签) config.filebrowserImageUploadUrl = '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images'; //上传图片按钮(标签) config.filebrowserFlashUploadUrl = '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Flash'; //上传Flash按钮(标签)
3.打开ckfinder目录下的config.ascx文件 ,配置ckfinder,需要配置的不多,重要的是以下两个。
public override bool CheckAuthentication() { // 窗体验证时用 return Request.IsAuthenticated; //return true; 不推荐使用 }
public override void SetConfig() { BaseUrl = "/ckfinder/userfiles/"; //文件,图片和flash等上传后的路径 }
四、一般配置技巧
config.language = 'zh-cn'; //设置中文语言 config.uiColor = '#AADC6E'; //编辑器颜色 config.font_names = '宋体;楷体_GB2312;新宋体;黑体;隶书;幼圆;微软雅黑;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana'; config.toolbarCanCollapse = false; config.toolbar_Full = [ ['Source','-','Preview','-','Templates'], ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'], ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], '/', ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['Link','Unlink','Anchor'], ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'], '/', ['Styles','Format','Font','FontSize'], ['TextColor','BGColor'], ['Maximize', 'ShowBlocks','-','About'] ]; config.toolbar_Basic = [ ['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink','-','About'] ]; config.width =810; //建议在控件那里设置 config.height = 300; //建议在控件那里设置 config.filebrowserBrowseUrl = './ckfinder/ckfinder.html'; //上传文件时浏览服务文件夹 config.filebrowserImageBrowseUrl = './ckfinder/ckfinder.html?Type=Images'; //上传图片时浏览服务文件夹 config.filebrowserFlashBrowseUrl = './ckfinder/ckfinder.html?Type=Flash'; //上传Flash时浏览服务文件夹 config.filebrowserUploadUrl = './ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files'; //上传文件按钮(标签) config.filebrowserImageUploadUrl = './ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images'; //上传图片按钮(标签) config.filebrowserFlashUploadUrl = './ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Flash'; //上传Flash按钮(标签)
五、总结
通过以上的描述,大家对CKEditor和CKFinder定有一点的了解,在此只讲解了它们在ASP.NET的使用,在其他语言平台的使用上,其配置内容基本上差不多。读者可以通过本文的思想,将其迁移到其他平台。相信大家定会做好的。附上运行后的效果图一张。
相关资料下载:http://download.csdn.net/detail/u014348368/7144037
- CKEditor和CKFinder在ASP.NET项目中安装,配置和使用详解
- Asp.net 中配置 CKEditor和CKFinder
- Asp.net 中配置 CKEditor和CKFinder
- Asp.net 中配置 CKEditor和CKFinder
- ASP.NET CKEditor和CKFinder配置
- ckeditor和ckfinder 在ASP.NET 中的使用
- asp.net下使用CKEditor和CKFinder
- ASP.NET项目中使用CKEditor +CKFinder 实现上传图片
- ASP.NET下CKEditor和CKFinder集成 配置
- CKEditor和CKFinder在ASP.NET中的应用
- (转)CKEditor和CKFinder在ASP.NET中的应用
- CKEditor和CKFinder在ASP.NET中的应用
- vs2010 asp.net项目中集成ckeditor和ckfinder最简单图文教程
- CKEditor+CKFinder+asp.net配置
- CKEditor+CKFinder+asp.net配置
- CKEditor+CKFinder+ASP.NET配置
- ASP ckeditor和ckfinder的使用
- PHP中CKEditor和CKFinder配置
- 802.11协议总结
- linux Crontab 使用
- 回复积分
- android之将图片转化为圆形图片
- 【javascript】javascript中的JSON.parse()和JSON.stringify()
- CKEditor和CKFinder在ASP.NET项目中安装,配置和使用详解
- java生成条形码
- QT下的几种透明效果
- 黑马程序员——【Java】IO——流合并、切割
- showAsDropDown && showAtLocation
- emwin,hello world
- PHP5.5新特征以及有可能的版本差异
- 关于jquery中工具函数
- 黑马程序员——【Java】IO——对象序列化