asp.net中配置与使用CKEditor编辑器图例

1、官方网站(http://cksource.com)上下载获得CKEditor和CKFinder的最新版。这里是我上传的我是用的版本及例子。

2、两个文件夹东西真的是很多,内容很全面,但是我们用的的东西不是全部,所以是挑选我们需要的东西添加到项目中去。这个是项目中CKEditor和CKFinder包含文件

3、在前台添加代码

 代码如下 复制代码

<head runat="server">
    <title></title>
    <script src="JS/ckedit/ckeditor.js" type="text/javascript"></script>  <!--必写的东西-->
    <style type="text/css">
        .ckeditor
        {}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine"
            CssClass="ckeditor" Height="207px" Width="517px"></asp:TextBox>
    </div>
    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="显示" /> <!--按钮点击 后台产生的事件-->
    </form>
</body>  

4、CKEditor 本身不自带上传功能,所以需要配合CKFinder才可以实现上传。

    (1)、项目添加引用CKFinder.dll

    (2)、配置CKEditor的config.js (目录:/CKEditor/config.js ) 在CKEDITOR.editorConfig函数里加上,不需要的功能可以去掉

代码如下:

 代码如下 复制代码

/*
Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/

CKEDITOR.editorConfig = function (config) {
    // Define changes to default configuration here. For example:
    // config.language = 'fr';
    // config.uiColor = '#AADC6E';

    var ckfinderPath = "/JS";   //注意这个地方的问题,JS是包含CKEditor和CKFinder的文件夹
    config.filebrowserBrowseUrl = ckfinderPath + '/ckfinder/ckfinder.html';
    config.filebrowserImageBrowseUrl = ckfinderPath + '/ckfinder/ckfinder.html?type=Images';
    config.filebrowserFlashBrowseUrl = ckfinderPath + '/ckfinder/ckfinder.html?type=Flash';
    config.filebrowserUploadUrl = ckfinderPath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files';
    config.filebrowserImageUploadUrl = ckfinderPath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images';
    config.filebrowserFlashUploadUrl = ckfinderPath + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Flash';
};

配置完成后CKEditor 就带有上传功能了,但假如上传图片,flash,以及其他文件时,文件如果用原来文件的名字,可能会出现重名的问题,

所以就要将文件名改为随机文件名。

5、修改CKFinder的源码。CKFinder自带有源码,目录:/CKFinde/_source,打开项目,

(1)、 打开/Settings/ConfigFile.cs文件,修改的地方,请看特殊标记

 代码如下 复制代码

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace CKFinder.Settings
{
    public class ConfigFile : System.Web.UI.UserControl
    {
        public string LicenseName;
        public string LicenseKey;
        public string BaseUrl;
        public string BaseDir;
        public bool RandomReName; //随机重命名
        public bool SecureImageUploads;
        public bool ForceSingleExtension;
        public bool CheckDoubleExtension;
        public bool CheckSizeAfterScaling;
        public bool DisallowUnsafeCharacters;
        public string[] HtmlExtensions;
        public string[] Plugins;
        public Hashtable PluginSettings;

        public string DefaultResourceTypes;

        private Thumbnails _Thumbnails;
        private Images _Images;
        private AccessControlManager _AccessControl;
        private ResourceTypeManager _ResourceType;

        private string[] _HideFolders;
        private string[] _HideFiles;

        internal Regex HideFoldersRegex;
        internal Regex HideFilesRegex;

        public string RoleSessionVar;

        private static ConfigFile _Current;

        public ConfigFile()
        {
            _Thumbnails = new Thumbnails();
            _Images = new Images();
            _AccessControl = new AccessControlManager();
            _ResourceType = new ResourceTypeManager();

            this.HideFolders = new string[ 0 ];
            this.HideFiles = new string[ 0 ];

            LicenseName = "";
            LicenseKey = "";
            BaseUrl = "/ckfinder/userfiles/";
            BaseDir = "";
            RandomReName = true;
            ForceSingleExtension = true;
            CheckSizeAfterScaling = true;
            DisallowUnsafeCharacters = true;
            CheckDoubleExtension = true;
            DefaultResourceTypes = "";
            HtmlExtensions = new string[ 0 ];
            Plugins = new string[ 0 ];
            PluginSettings = new Hashtable();
            RoleSessionVar = "";
        }    /*-----后面内容已经省略------------*/
    }
}  

  

(2)、打开/Connector/Config.cs文件,

定位60行左右,添加一个属性:
      

 代码如下 复制代码

public bool RandomReName

      {

        get { return Settings.ConfigFile.Current.RandomReName; }

      }

(3)、打开/Connector/CommandHandlers/FileUploadCommandHandler.cs文件,添加一句判断代码,下面显示的是部分代码,添加的代码已经标注

 代码如下 复制代码

      

using System;
using System.Web;
using System.Text.RegularExpressions;

namespace CKFinder.Connector.CommandHandlers
{
    public class FileUploadCommandHandler : CommandHandlerBase
    {
        public FileUploadCommandHandler()
            : base()
        {
        }
        public static string sFileName=null;
        public override void SendResponse( System.Web.HttpResponse response )
        {
            int iErrorNumber = 0;
            //string sFileName = "";
            string sFilePath = "";
            string sUnsafeFileName = "";

            try
            {
                this.CheckConnector();
                this.CheckRequest();

                if ( !this.CurrentFolder.CheckAcl( AccessControlRules.FileUpload ) )
                {
                    ConnectorException.Throw( Errors.Unauthorized );
                }

                HttpPostedFile oFile = null;
                if ( HttpContext.Current.Request.Files["upload"] != null )
                {
                    oFile = HttpContext.Current.Request.Files["upload"];
                }
                else if ( HttpContext.Current.Request.Files["NewFile"] != null )
                {
                    oFile = HttpContext.Current.Request.Files["NewFile"];
                }
                else if ( HttpContext.Current.Request.Files.AllKeys.Length > 0 )
                {
                    oFile = HttpContext.Current.Request.Files[HttpContext.Current.Request.Files.AllKeys[0]];
                }

                if ( oFile != null )
                {
                    sFileName = oFile.FileName;

                    if ( Config.Current.CheckDoubleExtension )
                        sFileName = this.CurrentFolder.ResourceTypeInfo.ReplaceInvalidDoubleExtensions( sFileName );

                    sUnsafeFileName = sFileName;
                   
                    if ( Config.Current.DisallowUnsafeCharacters )
                        sFileName = sFileName.Replace(";","_");

                    // Replace dots in the name with underscores (only one dot can be there... security issue).
                    if ( Config.Current.ForceSingleExtension )
                        sFileName = Regex.Replace( sFileName, @".(?![^.]*$)", "_", RegexOptions.None );

                    if ( sFileName != sUnsafeFileName )
                        iErrorNumber = Errors.UploadedInvalidNameRenamed;

                    if ( Connector.CheckFileName( sFileName ) && !Config.Current.CheckIsHiddenFile( sFileName ) )
                    {
                        if ( !Config.Current.CheckSizeAfterScaling && this.CurrentFolder.ResourceTypeInfo.MaxSize > 0 && oFile.ContentLength > this.CurrentFolder.ResourceTypeInfo.MaxSize )
                            ConnectorException.Throw( Errors.UploadedTooBig );

                        string sExtension = System.IO.Path.GetExtension( sFileName );
                        sExtension = sExtension.TrimStart( '.' );
                        if (Config.Current.RandomReName)  //使用随机名
                        {
                            sFileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "." + sExtension;
                        }            /*剩下的部分代码已经省略,详细代码请查看我的项目代码,下载地址为*/          }         }      }
    }
} 

4) 重新生成项目,在bin文件夹中,找到CKFinder.dll,对于第一个项目重新添加对于CKFinder.dll的引用,最后一步:打开/ckfinder/config.ascx

   在SetConfig()中,添加一属性:(其实这个加不加都可以的,因为之前有设置默认值,但使用原名时一定要设置为false)

    RandomReName = true;//上传完毕后使用随机文件名

好了,到此已经配置成功了

时间: 2024-08-16 06:54:05

asp.net中配置与使用CKEditor编辑器图例的相关文章

FCKeditor 2.6.5 ASP环境安装配置使用说明_网页编辑器

(1)精简,"言多必失",文件多了也是一种隐患.FCKEditor支持多种服务器脚本语言,实际使用的时候我们根本用不了那么多文件,我们要根据自己的需要对其进行精简. 对于ASP系统来说: FCKEditor根目录,仅保留"fckeditor.asp,fckconfig.js,fckeditor.js,fckpackager.xml,fckstyles.xml, fcktemplates.xml"这些文件以及editor目录.删除示例目录"_samples&

ASP.NET中CKEditor与CKFinder的配置使用

  这篇文章主要介绍了ASP.NET中CKEditor与CKFinder的配置使用的相关资料,需要的朋友可以参考下 将CKEditor 与 CKFinder 的包含在项目中,并添加程序集的引用 从http://cksource.com网站上下载CKEditor与CKFinder,并将这两个解压的项目之下,里面的 samples文件夹中是示例,是不需要的可以将samples文件夹直接删除,在ckeditor和ckfinder目录下各有bin目录,添加对bin目录下的release目录下的程序集的引

ASP.NET中集成百度编辑器UEditor

  本文给大家讲解的是如何在ASP.NET中集成百度编辑器UEditor的方法和具体的步奏,十分的详细,有需要的小伙伴可以参考下. 0.ueditor简介 UEditor是由百度WEB前端研发部开发的所见即所得的开源富文本编辑器,具有轻量.可定制.用户体验优秀等特点.开源基于BSD协议,所有源代码在协议允许范围内可自由修改和使用. UEditor官网:http://ueditor.baidu.com/website/index.html UEditor官方文档地址: http://fex.bai

ASP.NET中集成百度编辑器UEditor_实用技巧

0.ueditor简介 UEditor是由百度WEB前端研发部开发的所见即所得的开源富文本编辑器,具有轻量.可定制.用户体验优秀等特点.开源基于BSD协议,所有源代码在协议允许范围内可自由修改和使用. UEditor官网:http://ueditor.baidu.com/website/index.html UEditor官方文档地址: http://fex.baidu.com/ueditor/ 1.将ueditor包导入项目 将从官网上下载的开发包解压后包含到项目中 (注:最新的代码需要时基于

asp.net中使用kindeditor时,为什么编辑器好像缺少一排选项,比如改变字体的

问题描述 asp.net中使用kindeditor时,为什么编辑器好像缺少一排选项,比如改变字体的 解决方案 http://www.ablanxue.com/shtml/201508/27859_1.shtml 解决方案二: 以下是配置时的脚本 KindEditor.ready(function (K) { var editor1 = K.create("#content1", { cssPath: 'editor/plugins/code/prettify.css', uploadJ

ASP.NET中FCKEDITOR在线编辑器的用法_网页编辑器

你可以将FCKEDITOR放置到任何文件夹,默认情况下,将其放入到FCKEDITOR文件夹是最为简单的方法.如果你放入的文件夹使用别的名称,请修改配置文件夹中编辑器BasePath参数,如下所示: oFckeditor.BasePath="/Components/fckeditor/"; 另外,FCKEDITOR文件夹中所有以下划线开头的文件夹及文件,都是可选的,可以安全的从你的发布中删除.它们并不是编辑器运行时必需的 如何将FCKEDITOR整合进我的页面? 由于目前的版本提供的FC

ckeditor syntaxhighlighter代码高亮插件配置分享_网页编辑器

最近由于自己想做一个网站形式的代码库,自已写一个在线文本编辑器,对于现在的我来,确实是很不切实际,呵呵!再说了,现在有一个非常好的在线文本编辑器(ckeditor)了,我和必再去费这等功夫呢!有现成的,拿过用就是的呗!正所谓的拿来主义!不过这个在线文本编辑器,对于我们程序员来说有一个算是缺陷吧!没有代码高亮的功能!这样把代码贴上去,很不好看!今天晚上,我总是把他给弄出来了.当然也采在别人的肩膀上做成的.在此感谢他们的分享!费话不多说了!咱们进入正题吧! 首先去官方网站下载个ckeditor 其次

asp.net2.0(C#)中嵌入哪个在线文本编辑器最好用啊? 哪个功能最强大?

问题描述 asp.net2.0(C#)中嵌入哪个在线文本编辑器最好用啊?哪个功能最强大?最近接手做了一个网站,想请大家推荐一个功能强大的文本编辑器哪有下载地址?谢谢提供下载地址 解决方案 解决方案二:hhfeditor0417www.baidu.com搜下解决方案三:FC不错解决方案四:以前在ASP里面用过eWebEditor,还可以,但是在asp.net里的eWebEditor最高版本是3.0,那些商业版的找不到hhfeditor0417FCeWebEditor以上三个哪个好?对.net平台支

工具-怎么在vs2013中进行asp.net网站配置

问题描述 怎么在vs2013中进行asp.net网站配置 这个工具好像在以前的版本上有的,在vs2013中没找到,改怎么办呢?在百度上搜过,没看懂,求高人指点 解决方案 对了电脑操作系统是win8 解决方案二: 你要配置什么呢??? 解决方案三: 解决方案四: VS2013取消了从GUI上访问Web配置工具的功能,必须使用控制台启用 参考 http://blogs.msdn.com/b/webdev/archive/2013/08/19/asp-net-web-configuration-too