Asp. NET environment Integration CKEditor and CKEditor implement file upload

Source: Internet
Author: User

1, download ckeditor_aspnet_3.6.4 and ckfinder_aspnet_2.4 from http://ckeditor.com website;

2, unzip the downloaded file Ckeditor_aspnet_3.6.4.zip, get

Unzip the downloaded file Ckfinder_aspnet_2.4.zip, get

3, the Ckeditor_aspnet_3.6.4\_samples\bin folder under the CKEditor.NET.dll and CKEditor.NET.pdb, as well as Ckfinder_aspnet_2.4\ckfinder\bin CKFinder.dll and ckfinder.pdb files under the \debug folder are copied to the Project Bin folder;

4. Copy the CKEditor and Ckfinder folders into the project

5, modify the project configuration file, Web. config and ckeditor\config.js, ckfinder\config.ascx;

(1) Add between <system.web></system.web> in the Web. config file:

<pages>

<controls>

<add tagprefix= "CKEditor" assembly= "ckeditor.net" namespace= "Ckeditor.net"/>

</controls>

</pages>

(2) Ckeditor\config.js integration Specify the upload file browsing service, upload images, upload flash and other calls Ckfinder address, modified as follows:

Ckeditor.editorconfig = function (config)

{

Define changes to the default configuration here. For example:

Config.language = ' fr ';

Config.uicolor = ' #AADC6E ';

Config.language = ' ZH-CN ';

Config.filebrowserbrowseurl = '/ckfinder/ckfinder.html '; Browse service folders when uploading files

Config.filebrowserimagebrowseurl = '/ckfinder/ckfinder.html? Type=images '; Browse Service folders when uploading pictures

Config.filebrowserflashbrowseurl = '/ckfinder/ckfinder.html?  Type=flash '; Browse service folders when uploading flash

Config.filebrowseruploadurl = '/ckfinder/core/connector/aspx/connector.aspx?command=quickupload&type=files '; Upload file button (tab)

Config.filebrowserimageuploadurl = '/ckfinder/core/connector/aspx/connector.aspx?command=quickupload&type= Images '; Upload Picture button (label)

Config.filebrowserflashuploadurl = '/ckfinder/core/connector/aspx/connector.aspx?command=quickupload&type= Flash '; Upload Flash button (tag)

};

(3) Ckfinder\config.ascx Specifies whether authorization is required when uploading a file, default returns False, and is modified to true. (Note: It is not possible to return true directly in a formal project, but to verify that the user is logged on successfully!) )

public override bool Checkauthentication ()

{

Warning:do not simply return "true". By doing so, you are allowing

"Anyone" to upload and lists the files in your server. You must implement

Some kind of the session validation here. Even something very simple as ...

//

Return (session["isauthorized"]! = NULL && (BOOL) session["isauthorized"] = = true);

//

... where session["isauthorized"] is set to "true" as soon as the

User logs on your system.

return true;

}

6, create a new editor.aspx in the project, the source code is as follows:

<body>

<form id= "Form1" runat= "Server" >

<div>

<ckeditor:ckeditorcontrol id= "CKEditor1" runat= "Server" height= "$" basepath= "~/ckeditor" >

&lt;p&gt; This is some &lt;strong&gt;sample text&lt;/strong&gt;. You is using &lt;a href= "http://ckeditor.com/" &gt; ckeditor&lt;/a&gt;. &lt;/p&gt;

</CKEditor:CKEditorControl>

</div>

<asp:button id= "Button1" runat= "Server" onclick= "Button1_Click" text= "button"/>

<br/>

<asp:literal id= "Literal1" runat= "Server" ></asp:Literal>

</form>

</body>

In the Editor.aspx.cs file, enter:

protected void Button1_Click (object sender, EventArgs e)

{

Literal1.text = Ckeditor1.text;

}

7. Modify the Ckfinder to dynamically name the uploaded file, regenerate the CKFinder.dll file

Modify the source code of Ckfinder. Ckfinder from the source, directory:/ckfinde/_source
Create a new project in VS now point to Ckfinde/_source/ckfinder.net.sln
(1) Open/settings/configfile.cs file
position 27 Rows, add an attribute: public bool randomrename;//Random rename
position 63 Rows To assign a value to the property just now: Randomrename = true;//default value is True
Save close File
(2) Open/connector/config.cs file
position 61 rows and add an attribute:
Public bool Randomrename
        {
get {return Settings.ConfigFile.Current.RandomReName;}
        }
Save close File
(3) Open/connector/commandhandlers/fileuploadcommandhandler.cs file
position 84 lines, add a sentence to judge the code:
if (Config.Current.RandomReName)//Use random name
sfilename = DateTime.Now.ToString ("yyyymmddhhmmssfff") + "." + sextension;

Save close file, note: Here will jump out an error, sextension undefined, look up the definition of this variable, and then put it on the line after it.

(4) Rebuild the project and cover the/ckfinder/_source/bin/debug/ckfinder.dll/ckfinder/bin/release/ CKFinder.dll or site project remove the previously added reference and re-start the DLL from the Ckfinder.net project

Asp. NET environment Integration CKEditor and CKEditor implement file upload

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.