设为首页 加入收藏

TOP

CKEditor上传插件(一)
2014-11-24 12:41:32 】 浏览:6044
Tags:CKEditor 上传 插件

CKEditor上传插件


前言


CKEditor的上传插件不是免费的,特此开发一个与大家共享。此插件是基于ASP.NET MVC下开发的,如果是webform的用户或者其它语言的用户,可以参考把服务器端做相应的修改。看图:
\

大家可以看到Browse Button和Upload选项卡。下面分步详解三部分的实现:浏览服务器端图片或文件,上传图片或文件,CKEditor配置。

浏览服务器端图片或文件


先上图:
\

做了一个十分简易的浏览页面,左半部分是文件夹树,右半部分则显示当前文件夹中的图片。
ASP.NET MVC中Controller中浏览页面的action代码如下(即页面对应的服务器端代码):
public ActionResult Browse()
        {
            var type = Request.QueryString["Type"];
            var isImage = !string.IsNullOrEmpty(type) && type.Equals("Images", StringComparison.InvariantCultureIgnoreCase);
            ViewBag.IsImg = isImage;
            return View();
        }

不是ASP.NET MVC的用户,就把它当成是页面加载。 View(即页面代码)代码如下:
@{
    Layout = null;
}





    
  
    Browse
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/modernizr")
    
  
    
  
    <script src="/SHTracker/Scripts/TreeView/jquery.treeview.pack.js" type="text/java script">
    <script type="text/java script">
        $(document).ready(function () {
            $("body>aside>ul").treeview({
                animated: true,
                persist: "location",
                collapsed: true,
                unique: false
            });
        });
    
    


    
  
    
  
@if (!string.IsNullOrEmpty(Request.QueryString["folderpath"])) {
    @{ var imgTypes = new[] {".jpg", ".gif", ".png"}; } @foreach (var file in Directory.GetFiles(Server.MapPath("/" + Request.QueryString["folderpath"]))) { if ((bool) ViewBag.IsImg && imgTypes.Contains(Path.GetExtension(file.ToLower()))) {
  • } else {
  • @Path.GetFileName(file)
  • } }
}

页面引用了JQUERY,树状菜单部分是jquery的treeview插件,可自行GOOGLE,也可留言,我email给你。 其中的ICStars2_0.Common.UrlHelper.SafeAddQueryToURL方法,其实是我比较懒了随便GOOGLE了一个使用,就是给URL添加参数。代码如下:
#region = SafeAddQueryToURL =
        /// 
        /// Add a query to an URL.
        /// if the URL has not any query,then append the query key and value to it.
        /// if the URL has some queries, then check it if exists the query key already,replace the value, or append the key and value
        /// if the URL has any fragment, append fragments to the URL end.
        /// 
        /// 
  
   
        ///             string s = "http://blog.csdn.net/leewhoee/ a=1&b=2&c=3#tag";
        /// WL(SafeRemoveQueryFromURL("a",s));
        /// WL(SafeRemoveQueryFromURL("b",s));
        /// WL(SafeRemoveQueryFromURL("c",s));
        /// WL(SafeAddQueryToURL("d","new",s));
        /// WL(SafeAddQueryToURL("a","newvalue",s));
        ///            输出如下:
        ///            http://blog.csdn.net/leewhoee/ b=2&c=3#tag
        ///            http://blog.csdn.net/leewhoee/ a=1&c=3#tag
        ///            http://blog.csdn.net/leewhoee/ a=1&b=2#tag
        ///            http://blog.csdn.net/leewhoee/ a=1&b=2&c=3&d=new#tag
        ///            http://blog.csdn.net/leewhoee/ a=newvalue&b=2&c=3#tag
        /// 
  
        public static string SafeAddQueryToURL(string key, string value, string url)
        {
            int fragPos = url.LastIndexOf("#");
            string fragment = string.Empty;
            if (fragPos > -1)
            {
                fragment = url.Substring(fragPos);
                url = url.Substring(0, fragPos);
            }
            int querystart = url.IndexOf(" ");
            if (querystart < 0)
            {
                url += " " + key + "=" + value;
            }
            else
            {
                Regex reg = new Regex(@"( <=[&\ ])" + key + @"=[^\s&#]*", RegexOptions.Compiled);
                if (reg.IsMatch(url))
                    url = reg.Replace(url, key + "=" + value);
                else
                    url += "&" + key + "=" + value;
            }
            return url + fragment;
        }
        #endregion

        #region = SafeRemoveQueryFromURL =
        /// 
        /// Remove a query from url
        /// 
        /// 
        /// 
        /// 
  
        public static string SafeRemoveQueryFromURL(string key, string url)
        {
            Regex reg
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇NYOJ 663 弟弟的作业 下一篇UVA ShellSort

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目