asp.net(C#)下配置CKFinder

      学习了CKEditor的简单使用,也得知了它的缺陷,不支持图片等文件的上传,需要结合CKFinder,才能使它更perfect~

      究竟什么是CKFinder呢?我也是一知半解,应该主要是提供了图片、动画等文件的管理,支持上传、下载、查看等一些基本功能。网上大多数的文章都是介绍CKeditor与CKFinder相结合使用,访问CKfinder的网站,向我们展示了4中demo,一是单独在页面中使用CKfinder,二是CKFinder作为弹出窗口的方式使用,三则是与CKEditor相结合的使用,四是与FCKEditor(即上一代CKEditor)相结合使用。

      下面,就来介绍如何在页面中单独使用CKFinder吧~自己摸索的过程很慢,主要还是参考网络上的相关文章,结合CKFinder官网的英文指导,以及demo后得出的下文~,不过,有了CKEditor的使用经验,对于如何配置CKFinder,还是很有帮助的

--------------------------------------------------------------------------------------------------------------------

     在使用之前,需要先下载CKFinder点此进入官网下载吧~我使用的是CKFinder for ASP.NET,版本为CKFinder_aspnet_2.2.2,updated 03.07.2012

下载完成后,解压,我们也可以看到很多文件,_samples文件中提供了样例,_source文件中包含供二次开发人员使用的源码,skins文件中存放CKFinder的主题样式,userfiles文件则是默认的用户上传文件夹。

下面,就来介绍如何在Asp.net中使用CKFinder了~可参考官方的帮助文档

1.  首先,复制CKFinder文件夹至你的网站根目录下,即yourwebsite/ckfinder

Copy the distribution files to your web server and place them in the /ckfinder/ folder (or any other folder of your website)

2.  设置用于存放用户上传文件的文件夹,使其允许从Internet写入,在这里,我使用默认文件夹ckfinder/userfiles

Create a new folder on the server that will be used to store all uploaded files. By default, CKFinder is configured to use the /ckfinder/userfiles/ folder of your website.Make the user files folder writable for the Internet user. On Windows systems, give write permissions to the IUSR_<ServerName> user.

(我的是win7系统,就以此为例了~)选中userfiles文件夹,右键-属性-安全选项栏-编辑-添加,输入NETWORK SERVICE,确定。默认的NETWORK SERVICE用户的权限包括读取和执行、列出文件夹内容、读取,再添加——写入——权限,确定,就完成了。

3.  编辑ckfinder/config.ascx文件,修改两处地方(我也只是简单地使用,详见官网帮助文档)

Edit the config.ascx file. Make sure you have correctly set all settings in that file, and that you have enabled CKFinder. See Configuration for more information.

3.1 找到如下代码,将橙色处修改成红色处

public override bool CheckAuthentication()
    {
        // WARNING : DO NOT simply return "true". By doing so, you are allowing
        // "anyone" to upload and list the files in your server. You must implement
        // some kind of session validation here. Even something very simple as...
        //
        //        return ( Session[ "IsAuthorized" ] != null && (bool)Session[ "IsAuthorized" ] == true );
        //
        // ... where Session[ "IsAuthorized" ] is set to "true" as soon as the
        // user logs on your system.

        //return false;
        return true;//允许用户浏览服务器
    }

3.2 找到如下

// The base URL used to reach files in CKFinder through the browser.
        BaseUrl = "/ckfinder/userfiles/";

修改为(其中,myckfinder为我的网站项目名)

// The base URL used to reach files in CKFinder through the browser.
        BaseUrl = "/myckfinder/ckfinder/userfiles/";

 3.3 补充一点,由于我们下载的是demo版,所以使用时会有——文字提示,让我们购买之类的——

 这篇博文提供了解决方法

4.  添加.dll文件的引用,位于ckfinder/bin/Release下的CKFinder.dll文件

Create a reference to the CKFinder.dll file in your project by using one of the methods described below:

方法一:将其复制到网站的bin目录下即可 方法二:在网站中,添加.dll文件的引用 5.  注册该控件 如果你仅在一个页面中使用该控件,只要在aspx页面中加入如下代码即可:
<%@Register Assembly="CKfinder" Namespace="CKFinder" TagPrefix="CKFinder"%>

如果你要在多个页面中使用该控件,则需配置web.config文件,在<system.web><pages><controls>下插入如下代码即可:

<add tagPrefix="CKFinder" assembly="CKFinder" namespace="CKFinder"/>
  --------------------------------------------------------------------------------------------------------------------   到这里呢,CKFinder的配置就算完成了,可以浏览_sample下的文件,查看是否配置成功吧   --------------------------------------------------------------------------------------------------------------------  

 6.  在页面中单独使用CKFinder

看完官网提供的demo后,对于如何使用CKfinder,应该很简单了

6.1 在页面中加入javascript语句,如下:

<script type="text/javascript">

// This is a sample function which is called when a file is selected in CKFinder.
function ShowFileInfo( fileUrl, data )
{
    var msg = 'The selected URL is: ' + fileUrl + '\n\n';
    // Display additional information available in the "data" object.
    // For example, the size of a file (in KB) is available in the data["fileSize"] variable.
    if ( fileUrl != data['fileUrl'] )
        msg += 'File url: ' + data['fileUrl'] + '\n';
    msg += 'File size: ' + data['fileSize'] + 'KB\n';
    msg += 'Last modified: ' + data['fileDate'];

    alert( msg );
}

</script>

6.2 调用CKFinder控件,使用代码如下:

<CKFinder:FileBrowser ID="FileBrowser1" BasePath="./ckfinder/" SelectFunction="ShowFileInfo" Height="600" runat="server"></CKFinder:FileBrowser>

 

-------------------------------------------------------------------------------------------------------------------- 

这样就完成了,浏览该网页就可以使用CKFinder了~

 --------------------------------------------------------------------------------------------------------------------

 

7.  CKEditor与CKFinder的相结合使用

在页面中添加完成CKEditor后,只要在aspx.cs文件中加入如下代码即可:

protected void Page_Load(object sender, EventArgs e)
    {
        CKFinder.FileBrowser _FileBrowser = new CKFinder.FileBrowser();
        _FileBrowser.BasePath = "./ckfinder/";
        _FileBrowser.SetupCKEditor(CKEditor1);
    }

转载于:https://www.cnblogs.com/YummyPumpkin/archive/2012/08/14/2633472.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值