sujanr
sujanr

Reputation: 13

Image uploading using CKEditor in asp.net mvc

I am using CKEditor in my application as rich text box. It is used to provide bullets and numbering. Now we need to upload images in between the text. So how can i accomplish this? What all configuraion is to be set? Also should i use CKFinder for this? If so please detail me on this.

Upvotes: 0

Views: 2296

Answers (1)

Hong Van Vit
Hong Van Vit

Reputation: 2986

You can try like this:

In view.

filebrowserImageUploadUrl: '../../Upload/uploadnow'

In Controller

public ActionResult uploadnow(HttpPostedFileWrapper upload, string CKEditorFuncNum)
    {
        string path = "";
        string pathWeb ="";
        if (upload != null)
        {
            string ImageName = upload.FileName;
            string extention = Path.GetExtension(ImageName);
            string name = DateTime.Now.ToString("yyMMddhhmmssms");
            ImageName = name + extention;
            pathWeb = "/images/uploads/" + ImageName;
            path = System.IO.Path.Combine(Server.MapPath("~/images/uploads"), ImageName);
            upload.SaveAs(path);
            HttpContext.Response.Write("<script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + pathWeb + "\");</script>");
            HttpContext.Response.End();
        }
        return View();
    }

Upvotes: 1

Related Questions