Enable the file upload in ck-editor using C#
==========Add the following script in head tag================
<script type="text/javascript" language="javascript">
$(function () {
CKEDITOR.replace('<%=CKEditorControl1.ClientID %>', { filebrowserImageUploadUrl: 'Upload.ashx' });
});
</script>
=========Create ASHX handler page for uploading=================
<%@ WebHandler Language="C#" Class="Upload" %>
using System;
using System.Web;
public class Upload : IHttpHandler {
public void ProcessRequest (HttpContext context) {
databaseprocess db = new databaseprocess();
string appLink = "Web Site URL";
HttpPostedFile uploads = context.Request.Files["upload"];
string CKEditorFuncNum = context.Request["CKEditorFuncNum"];
string file = System.IO.Path.GetFileName(uploads.FileName);
uploads.SaveAs(context.Server.MapPath("../images/") + file);
string url = "";
url = appLink + "/images/" + file;
context.Response.Write("<script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + url + "\");</script>");
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}
<script type="text/javascript" language="javascript">
$(function () {
CKEDITOR.replace('<%=CKEditorControl1.ClientID %>', { filebrowserImageUploadUrl: 'Upload.ashx' });
});
</script>
=========Create ASHX handler page for uploading=================
<%@ WebHandler Language="C#" Class="Upload" %>
using System;
using System.Web;
public class Upload : IHttpHandler {
public void ProcessRequest (HttpContext context) {
databaseprocess db = new databaseprocess();
string appLink = "Web Site URL";
HttpPostedFile uploads = context.Request.Files["upload"];
string CKEditorFuncNum = context.Request["CKEditorFuncNum"];
string file = System.IO.Path.GetFileName(uploads.FileName);
uploads.SaveAs(context.Server.MapPath("../images/") + file);
string url = "";
url = appLink + "/images/" + file;
context.Response.Write("<script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + url + "\");</script>");
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}
Comments
Post a Comment