Last active
December 8, 2021 17:22
-
-
Save afsharm/5660844 to your computer and use it in GitHub Desktop.
How to add a simple file upload functionality to CKEditor in ASP.NET MVC. Use CKEditor as CKEDITOR.replace('Description', { filebrowserImageUploadUrl: '/ControllerName/UploadImage' }); It is an updated version of http://arturito.net/2010/11/03/file-and-image-upload-with-asp-net-mvc2-with-ckeditor-wysiwyg-rich-text-editor/ For more information see …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[AcceptVerbs(HttpVerbs.Post)] | |
public ActionResult UploadImage(HttpPostedFileBase upload, string CKEditorFuncNum, string CKEditor, string langCode) | |
{ | |
//http://stackoverflow.com/a/4088194/167670 | |
//http://arturito.net/2010/11/03/file-and-image-upload-with-asp-net-mvc2-with-ckeditor-wysiwyg-rich-text-editor/ | |
//http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx | |
if (upload.ContentLength <= 0) | |
return null; | |
// here logic to upload image | |
// and get file path of the image | |
const string uploadFolder = "UserImages"; | |
var fileName = Path.GetFileName(upload.FileName); | |
var path = Path.Combine(Server.MapPath(string.Format("~/{0}", uploadFolder)), fileName); | |
upload.SaveAs(path); | |
var url = string.Format("{0}{1}/{2}/{3}", Request.Url.GetLeftPart(UriPartial.Authority), | |
Request.ApplicationPath == "/" ? string.Empty : Request.ApplicationPath, | |
uploadFolder, fileName); | |
// passing message success/failure | |
const string message = "Image was saved correctly"; | |
// since it is an ajax request it requires this string | |
var output = string.Format( | |
"<html><body><script>window.parent.CKEDITOR.tools.callFunction({0}, \"{1}\", \"{2}\");</script></body></html>", | |
CKEditorFuncNum, url, message); | |
return Content(output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
its runs ok, but when i click ok button it shows this message "Images source URL is missing " .
How can i solve this problem ???