如何在asp.net 4.0中使用ckeditor启用图像上传

时间:2019-05-14 10:02:31

标签: asp.net c#-4.0 ckeditor

我有一些接受富文本格式的页面。我只是使用ckeditor控件。它加载得很好。但无法显示用于上传图片的图片浏览器标签。这是我的html标记:

<script type="text/javascript">
        $(function () {
            CKEDITOR.replace('<%=CKEditor1.ClientID %>', { filebrowserImageUploadUrl: 'Upload.ashx' });
        });
    </script>
<tr>
                                                <td style="width: 20%">Template Body
                                                </td>
                                                <td>
                                                    <CKEditor:CKEditorControl ID="CKEditor1" runat="server" ValidationGroup="AddNewTemplate" PasteFromWordRemoveFontStyles="False"></CKEditor:CKEditorControl>
                                                    <asp:CustomValidator ID="CustomValidator2" runat="server"
                                                        ErrorMessage="Template body is required."
                                                        OnServerValidate="CustomValidator2_ServerValidate"
                                                        ValidationGroup="AddNewTemplate" ForeColor="Red"></asp:CustomValidator>
                                                </td>
                                            </tr>

这是我上传的用于图像上传的ashx文件。

<%@ WebHandler Language="C#" Class="Upload" %>

using System;
using System.Web;
using System.Configuration;
using System.IO;
public class Upload : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        HttpPostedFile uploads = context.Request.Files["upload"];
       string CKEditorFuncNum = context.Request["CKEditorFuncNum"];
       string file = DateTime.Now.ToString("ddMMyyyy_HHmmss") + Path.GetExtension(uploads.FileName);
       uploads.SaveAs(context.Server.MapPath(".") + "\\EmailImages\\" + file);
       //provide direct URL here
       string url = "/EmailImages/" + file;  
      context.Response.Write("<script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + url + "\");</script>");
      context.Response.End();                     
    }

    public bool IsReusable {
        get { return false; }
    }
}

,这是我的ckeditor屏幕,没有上载标签: enter image description here

1 个答案:

答案 0 :(得分:0)

是的,我们可以使用CKEditor控件做一件事。仅查看页面上显示的CKeditor控件的属性。然后只需将Upload.ashx文件名分配给该属性即可。

enter image description here