Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

USING CKEDITOR WITH ASP.NET AND HENCE UPDATING FILE ON SERVER..

0.00/5 (No votes)
3 Aug 2010 1  
IT SHOWS HOW TO USE NEW CKEDITOR (!FCKEDITOR) TO BE USED WITH ASP.NET

THE START UP:-

This article shows you how to implement THE NEW CKEDITOR3.X within your webpage. Although its easier to show it in webpage but it becomes a bit messy when the matter comes to updating back the posted data. however, before proceeding I would suggest newbies to opt for ajax.net library, than to ckeditor.

First of all download the ckeditor, extract it ,double click the extracted folder,and thus copy the directory ckeditor (dont go beyond) to the project folder as shown in my examplecode.


THE PROGRAM:-

Paste following  line into your head section of default.aspx

<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>

and your client is able to get access to these scripts..

Now

  1. drag a textbox into your form tag & set its property to multiline textbox so it will change into textarea at client.
  2. in the code behind file write:-

 


 

protected void Page_Load(object sender, EventArgs e)

{// FOR C# 3.0 OR BELOW

/* Page.RegisterStartupScript("js2","<script type=\"text/javascript\"> window.onload = function() {CKEDITOR.replace( 'editor1' );};</script>"); */

//FOR 3.5 OR 4.0

ClientScript.RegisterStartupScript(cstype, Type cstype = this.GetType();"js2", "<script type=\"text/javascript\"> window.onload = function() {CKEDITOR.replace( '" textbox.ID+"' );};</script> ";

 


 

AND DONT FORGET TO ADD THIS TO HEAD SECTION

 

<script type="text/javascript">

 

window.onerror =function(){return true;}   

</script>

 

 

YOU ARE READY TO USE YOUR CKEDITOR!!!!!!!!!!!!!!!!!!

 


 

 copy the edit.aspx file (my code sample) this page shows all the files in your project (.htm or .aspx).

click anyone of the file & it will be brought inside the editor

insert this code into your page_load method (it loads to ckeditor):-

 


s = Request.QueryString["qr"];
if (!IsPostBack)
{
if (s != null)
{
fs = new FileStream(System.Configuration.ConfigurationManager.AppSettings["rd"].Trim() + s, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
StreamReader sw = new StreamReader(fs);
String data = sw.ReadToEnd();


shot = data.Substring(0, data.IndexOf("<body>"));
editor1.Text = String.Format("{0}", data.Substring(data.IndexOf("<body>"), data.LastIndexOf("</body>") - data.IndexOf("<body>") - 1));
sw.Close();
fs = null;

}
}


 

  • Add a button to your form and its onclick event should have the following code:-

protected void Button1_Click(object sender, EventArgs e)
{
My.Visible = true;
if(s!=null)
{
fs = new FileStream(System.Configuration.ConfigurationManager.AppSettings["rd"].Trim() + s, FileMode.Truncate, FileAccess.ReadWrite, FileShare.ReadWrite);
StreamWriter se = new StreamWriter(fs);
se.WriteLine(String.Format("{0} <body>{1}</body></html>", shot, editor1.Text));
se.Close();

My.InnerHtml = String.Format("<iframe id=\"polo\" width=\"1200\" src=\"{0}\"></iframe>", s);
}
}

 


 

  • lastly add following lines to your web.config

<appSettings>
<add key="C:\Users\Administrator\Documents\Visual Studio 2008\Projects\CK_editor\CK_editor\Web.configrd" value="C:\Users\Administrator\Documents\Visual Studio 2008\Projects\CK_editor\CK_editor\"/>

//values are of my computer set it to yours...
</appSettings>

CHEERS YOU R READY TO UPDATE YOUR PAGES!!!!!!!!!!!!!!!!!

 

IF SOURCE CODE IS NOT AVAILABLE AT CODE-PROJECT THEN DOWNLOAD IT FROM HERE:-

CK_EDITOR-PROJECT

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here