简体   繁体   English

如何将NicEdit RTF编辑器与asp.net C#(.aspx)页面集成

[英]How to integrate NicEdit rich text editor with asp.net C# (.aspx) pages

I found many solution for Text editing in web pages, But one of most handy and light weight Text Editor is NiEditor . 我在网页上找到了许多用于文本编辑的解决方案,但是最方便,重量轻的文本编辑器之一是NiEditor I was burning my head to upload image by editor to my own server. 我很想把编辑器将图像上传到自己的服务器上。 By default editor uploads images on [IMGUR] server. 默认情况下,编辑器将图像上传到[IMGUR]服务器上。 My question is how to upload image(s) to my own server instead of IMGUR server? 我的问题是如何将图像上传到我自己的服务器而不是IMGUR服务器? Image Link 图片链接

Here I found nice solution for image uploading in .net. 在这里,我找到了在.net中上传图片的好方法。 Generic Handlers are the best option for image uploading. 通用处理程序是图像上传的最佳选择。 Please follow the steps below to integrate NicEditor with asp.net using C#. 请按照以下步骤使用C#将NicEditor与asp.net集成。

  1. Download latest nicEdit.js from nicedit.com. 从nicedit.com下载最新的nicEdit.js。

  2. Modify line no 1888 with the below code 使用以下代码修改1888行

 nicURI: "images.ashx"
  1. Create a generic handler to upload image named images.ashx. 创建一个通用处理程序以上传名为images.ashx的图像。
  2. Write the below code in yourhandler.ashx file inside public void ProcessRequest(HttpContext context) . 在public void ProcessRequest(HttpContext context)内的yourhandler.ashx文件中编写以下代码。

     string baseImageLocation = HttpContext.Current.Server.MapPath("~/Admin/imgs/"); HttpPostedFile Files; Files = context.Request.Files[0]; // Load File collection into HttpFileCollection variable. //Files.ContentLength; //Files.ContentType; if (Files != null && Files.ContentLength > 0) { System.IO.Stream fileStream = Files.InputStream; fileStream.Position = 0; byte[] fileContents = new byte[Files.ContentLength]; fileStream.Read(fileContents, 0, Files.ContentLength); string fileExt = System.IO.Path.GetExtension(Files.FileName).ToLower(); string fileName = Path.GetFileName(Files.FileName); System.Drawing.Image image = null; if (fileName != null) { if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".jpg" || fileExt == ".png" || fileExt == ".jpeg") { image = System.Drawing.Image.FromStream(new System.IO.MemoryStream(fileContents)); if (System.IO.File.Exists(baseImageLocation + "/" + fileName)) fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + fileExt; Files.SaveAs(baseImageLocation + fileName); } } string link = VirtualPathUtility.ToAbsolute("~/Admin/imgs/") + fileName; string imageHeight = image.Height.ToString(); string imageWidth = image.Width.ToString(); string json = ""; json += "{" + "\\"links\\": \\"" + link + "\\"," + "\\"width\\": \\"" + imageWidth + "\\"," + "\\"height\\": \\"" + imageHeight + "\\"" + "}"; context.Response.ContentType = "application/json"; context.Response.Write(json); } 
  3. Please be noted , place your nicEdit.js file and yourhandler.ashx file in the same folder so that it can be easily accessed path of the handler. 请注意,将nicEdit.js文件和yourhandler.ashx文件放在同一文件夹中,以便可以轻松访问处理程序的路径。

  4. Create image folder to upload images (uploaded by editor) in solution directory. 创建图像文件夹以在解决方案目录中上传图像(由编辑器上传)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM