How to Use FCKeditor in ASP. NET

Source: Internet
Author: User
How to Use FCKeditor in ASP. NET
How to Use FCKeditor in ASP. NET 2.0?ASP. NET IntegrationFCKeditor is a JavaScript Application that runs in the browser. you can use it without any kind of strict server side integration, if you want. but, a more clean and powerful way to use it, is by choosing a server side integration package that fit your needs. for ASP. net, a parallel package is available to make it possible to use FCKeditor as any other control on webforms. this package is called FCKeditor. net. it is very easy to use FCKeditor in your asp. net web pages. just follow these steps.PrerequisitesYou must have downloaded and installed (copied it in your web site) the latest version of FCKeditor editor before proceeding with these steps. the FCKeditor. net Package doesn' t include the core of the Editor (JavaScript scripts to be placed in the/FCKeditor/directory of your site ). you can download it from the following URL:
Http://sourceforge.net/project/showfiles.php? Group_id = 75348 & package_id = 75845Step 1Suppose that the editor is installed in"/FCKeditor/"Path of your web site. Now you need to download the FCKeditor ASP. Net Control DLL to use in your pages. You can find the last version here: http://sourceforge.net/project/showfiles.php? Group_id = 75348 & package_id = 137125Step 2The downloaded ZIP file contains the original source code of the control and a compiled version of it (the "bin/release/Fredck. fckeditorv2.dll"File "). you most probably will not need to make changes in the source, so just consider the compiled DLL file, and just create a reference to it in your project. you have two options to do that:
  • Manually copying the fredck. fckeditorv2.dll file to the "bin" Directory of your web site.
  • Right-clicking in "references" in your Visual Studio. NET project and select the fredck. fckeditorv2.dll file from the directory you have saved it.
  • You can include the control in your Visual Studio. net controls toolbox. just right-click on it and select "Add/Remove items... ". then, just point to the fredck. fckeditorv2.dll file.
  • Make sure that you have the latest version of the DLL. It may be worthwhile to recompile from the source if you are having issues getting the upload and connector features to work.
Step 3Now the editor is ready to be used in your site, so just create a ASP. NET page and, to create an instance of the editor, you have two options:
  • Just drag and drop the control in your page from the Toolbox (if you have added it to the toolbox as described at "Step 2 ").
  • Include the following line in the top of your ASP. NET page source:
<% @ Register tagprefix = "fckeditorv2" namespace = "fredck. fckeditorv2 "assembly =" fredck. fckeditorv2 "%> and then adding the editor tag inside a <form runat =" server ">:< fckeditorv2: FCKeditor id =" fckeditor1 "basepath = "~ /FCKeditor/"runat =" server "/> note thatBasepathProperty points to the directory where the FCKeditor scripts have been copied.The complete sample<% @ Page validaterequest = "false" Language = "VB" autoeventwireup = "false" %> <% @ register tagprefix = "fckeditorv2" namespace = "fredck. fckeditorv2 "assembly =" fredck. fckeditorv2 "%> <HTML> File Browser and quick uploadFCKeditor comes with a default file browser that makes it easy to user to upload files and images to the server, as well as browse the available files for reuse. it is also available a "quick upload" feature to quickly upload files and create links for them. this default system is integrated with all server side extensions ages supported by FCKeditor. you just need to make a simple configuration to indicate which one you are using. to do that for ASP. net, just openFckconfig. jsFile in the directory where you have copied the FCKeditor core package. Look for_ FilebrowserlanguageAnd_ QuickuploadlanguageEntries and set their values'Aspx'. You must prepare your site to accept the uploaded files and their relative directory. structure. By default FCKeditor. NET will look forUserfilesDirectory in the root of the web site, and place all files there. So, just create that directory. Important: You must grant the necessary privileges toASPnetAnd/orIUSR _ <computername>Users to be able to write files and create directories in the userfiles directory.SamplesYou can find some samples on how to use the editor in the "_ samples/aspx" directory of the FCKeditor. net distribution package. to install the samples, just copy that directory to the _ samples directory found in the FCKeditor core package installation.Minimum installation sampleThis is a fictitious structure of a ASP. NET web site using FCKeditor. As we can see, this site is composed:
  • TheFredck. fckeditorv2.dllFile, which has been downloaded from the FCKeditor. Net Package and simply copied toBinDirectory in the Web site root. (See "Steps 1 and 2 ")
  • TheFCKeditorDirectory, where the editor scripts have been copied (from the FCKeditor core package). (See "prerequisites ")
  • TheUserfilesDirectory, where user uploaded files will be placed.
  • A simpleMypage. aspxPage that uses the editor, with the above sample code on it. (See "Step 3 ")
TipsYou can set the default userfiles path in your web. config file, so it will be set to all FCKeditor instances you use in your web site: <shortettings> <add key = "FCKeditor: userfilespath "value ="/wherever/directory/"/> </receivettings>ASP. NET 1.1 and 2.0On the pages where FCKeditor has to be encoded, it's recommended to set the validaterequest property of the page ctictive to false: <% @ page Language = "VB" inherits = "fredck. fckeditorv2.filebrowserconnector "autoeventwireup =" false "validaterequest =" false "%> this is because some input created by the editor may be considered dangerous by. net Framework.ASP. NET 2.0 and themesSpecial note if you are using ASP. NET 2.0 and themes: You must open up "Editor/filemanager/upload/aspx/upload. aspx "and" Editor/filemanager/Browser/default/connectors/aspx/connector. aspx "and modify the first line to addTheme = ""AndStylesheettheme = ""As follows: <% @ page Language = "VB" inherits = "fredck. fckeditorv2.filebrowserconnector" autoeventwireup = "false" theme = "" stylesheettheme = "" %>Changing the userfilespath by codeSuppose you wowould like to modify the location of user uploaded files. you can do so without dynamically adding the control, but you shoshould do so in the page init, not the page load. for example, here is an example which uses files for each team in the same directory: protected sub page_init (byval sender as object, byval e as system. eventargs) handles me. init SESSION ("FCKeditor: userfilespath") = "~ /App_images/"& _ teamnameend subAdd an editor dynamically in your codeIf you use an application method (virtual directory), then set the base path in the web. config File: for example if this is your FCKeditor path "C:/inetpub/wwwroot/virtualdir/FCKeditor/" add this: <add key = "FCKeditor: basepath" value = "~ /FCKeditor/"/> I use a session to set the filebrowsers path, add the session variable before you make the control session (" FCKeditor: userfilespath ") = "/virtualdir/userfiles/" I use the request object in order to establish the correct basepath. I suppose that the correct path is on "http: // Fck in a user controlIn fck 2.4, the Instance name of a fck editor inside a user control will be its clientid (the dom id). In 2.3, it was the DOM name.Best summarized setup (for ASP. NET 2.0)1. downloads
  1. Download http://sourceforge.net/project/showfiles.php? Group_id = 75348 & package_id = 75845
  2. Download http://sourceforge.net/project/showfiles.php? Group_id = 75348 & package_id = 137125
A) has editor file (XML files & configuration files) B) This has Asp.net 2.0 DLL in it (and aspx examples) 2. minimum install setup. locate fredck. fckeditorv2.dll and put in your bin directory (from B's download) B. create a directory for FCKeditor and put the core files from there (from a's download) C. create a directory for userfiles and change the rights of this folder so Internet users can modify it3. put below in Web. config File <appsettings> <add key = "FCKeditor: basepath "value =" [path where editor is] "/>/* FCKeditor's path */<add key =" FCKeditor: userfilespath "value =" [path users upload files] "/>/* User Files path */</appsettings> 4. special note if you are using ASP. NET 2.0 and themes: You must open up. "Editor/filemanager/upload/aspx/upload. aspx ". "Editor/filemanager/Browser/default/connectors/aspx/connector. aspx "and modify the first line to add theme =" "And stylesheettheme =" "as follows: <% @ page Language =" VB "inherits =" fredck. fckeditorv2.filebrowserconnector "autoeventwireup =" false "theme =" "stylesheettheme =" "%> 5. add below to every page that will use FCKeditor <% @ register tagprefix = "fckeditorv2" namespace = "fredck. fckeditorv2 "assembly =" fredck. fckeditorv2 "%> also set validaterequest to false like below... <% @ page Language = "VB" inherits = "fredck. fckeditorv2.filebrowserconnector "autoeventwireup =" false "validaterequest =" false "%> 6. to add editor dynamically by code:
  • If you use an application method (virtual directory), then set the base path in the web. config file:
For example if this is your FCKeditor path "C:/inetpub/wwwroot/virtualdir/FCKeditor/" add this: <add key = "FCKeditor: basepath" value = "~ /FCKeditor/"/>
  • I use a session to set the filebrowsers path, add the session variable before you make the control (useful when dynamic directories are needed)
Session ("FCKeditor: userfilespath") = "/virtualdir/userfiles /"
  • I use the request object in order to establish the correct basepath. I suppose that the correct path is on "http: //
Fckeditor1.basepath = request. applicationpath + "/FCKeditor /";
  • Add the control to the page:
Dim FCKeditor as new fredck. fckeditorv2.fckeditorfckeditor. imagebrowserurl = "http: // localhost/virtualdir/FCKeditor/Editor/filemanager/Browser/default/browser.html? Type = Image & connector = connectors/aspx/connector. aspx "FCKeditor. id = "dynamicname" FCKeditor. value = "the text you want in the fck Editor" FCKeditor. skinpath = "skins/silver/" FCKeditor. toolbarset = "default" myform. controls. add (FCKeditor)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.