Config FCKeditor to Upload picture in ASP.Net MVC 3

What’s Needed:
Download FCKeditor.Net 2.6.4 from this page http://ckeditor.com/download
 Unzip the FCKeditor.Net_2.6.4.zip file you downloaded above. There are several files and directories that are expanded from the zip file we are only interested in one of them, FredCK.FCKeditorV2.dll, which you will find in the bin\release\2.0 directory.
Next: we will implement by flow:
1. Create new a project
2. Create new a folder named fckeditor  in a Scripts folder.
3. Copy editor folder and fckconfig.js, fckeditor.js, fckstyles.xml from folder with is unzip and paste to fckeditor folder.
4. Reference FredCK.FCKeditorV2.dll to project.
5. The next step is to modify the fckconfig.js file. About one page’s worth from the bottom of the fckconfig.js file are two lines
var _FileBrowserLanguage     = 'php' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'php'; // asp | aspx | cfm | lasso | perl | php | py
These need to be changed to:
var _FileBrowserLanguage     = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'aspx'; // asp | aspx | cfm | lasso | perl | php | py
6. Next is modification of the file at FCKeditor\editor\filemanager\connectors\aspx\config.ascx. First modify the CheckAuthentication function. By default it is set to return false, but in order for the file uploader to work this function needs to return true.
private bool CheckAuthentication()
	{
		// WARNING : DO NOT simply return "true". By doing so, you are allowing
		// "anyone" to upload and list the files in your server. You must implement
		// some kind of 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 in your system.

        return false;
	}
These need to be changed to:
private bool CheckAuthentication()
	{
		// WARNING : DO NOT simply return "true". By doing so, you are allowing
		// "anyone" to upload and list the files in your server. You must implement
		// some kind of 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 in your system.

        return true;
	}
8. Edit UserFilesPath and UserFilesAbsolutePath in SetConfig method
// URL path to user files.
        UserFilesPath = VirtualPathUtility.ToAbsolute("~/Content/imageUpload/");

		// The connector tries to resolve the above UserFilesPath automatically.
		// Use the following setting it you prefer to explicitely specify the
		// absolute path. Examples: 'C:\\MySite\\userfiles\\' or '/root/mysite/userfiles/'.
		// Attention: The above 'UserFilesPath' URL must point to the same directory.
        UserFilesAbsolutePath = HttpContext.Current.Server.MapPath("~/Content/imageUpload/");
8. Run application now.
Advertisements
This entry was posted in ASP.NET MVC. Bookmark the permalink.

2 Responses to Config FCKeditor to Upload picture in ASP.Net MVC 3

  1. Pingback: Using FCKeditor in ASP.Net MVC 3 | Nhat's space

  2. Andre says:

    I didn´t manage… There is no upload tab when I click in Images…. And the file config.ascx is made for MVC2, I guess…. Let me know if i am wrong.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s