Introduction

CP Article Editor allows you to create/edit articles for CodeProject without internet connection requirement. You can also login to backup (both your articles and related images) and edit your published articles using this program. It is very small in size and portable.

(Click on the images to view the full sized images in a new window.)

Background

Let's learn or remember something that we will need to understand the source code.

Asynchronous Operations

Asynchronous operations work separately and they have their own threads. If we need to execute codes after they finished their works we can't write these codes below the method it starts them. Because they don't block the method they are called from. Another thing that we must know is that a thread can't access an object created on a different thread...

Generally we are using events for operations that must be done after an asynchronous method finished its mission or an event occured. But I used a different way for this purpose and I think it is relatively simpler to understand.

Suppose that we have a thread and we want to call a function after our thread finished its work:

A thread can't make any change directly on a visual object owned by an UI thread. And we can't be sure about that the user will not use codes in our new thread to access visual controls created by the UI thread. This is why we need an invoker object.

Usage:

privatevoid button1_Click(object sender, EventArgs e)
{
Action myAction = new Action(() =>
{
MessageBox.Show("Finished.");
this.Text = "I can access all the objects without any trouble." +
"Because I will be invoked by the thread of this form.";
});
Example example = new Example(myAction, this);
example.doSomeWorksAsynchronously(); // It doesn't block the current thread.
}

CKEditor

CKEditor is an open source WYSIWYG editor that can be integrated with web pages easily. I used it inside a webbrowser in this project.

I customized the toolbar and removed unneccessary plugins to reduce total size. Additionally I modified image.js plugin to make using relative urls possible:

Screenshots

If you want to backup your published articles to edit or just to save them you can enter your email and password to login. Your articles will be listed after you logged in:

When you choosed one of them, some informations about it will appear:

You can write a new article or edit an existing one even if you are not connected to the internet:

Transferring Articles To CodeProject's Online Editor

Select "Copy source to the clipboard" from the right-click menu.(Note that all absolute image paths are converted to relative paths. So you don't have to change anything on copied html codes.)

Open codeproject online editor.

Click on "HTML" button to switch to HTML mode:

Paste your contents. (CTRL+V)

Click again on "HTML" button to switch back to design mode...

Points Of Interest

Let me list things that we can learn while examining the source codes:

WYSIWYG html editor in .NET.

How to use ckeditor in .NET?

How to call a javascript function inside a WebBrowser from a c# function?

Automated login and data extraction.

Using Actions instead of Events for asynchronous functions in c#.

Disabling click sound in a WebBrowser control.

Downloading files from internet in c#.

History

15 December 2013 (v1.0.4)

Article listing and login methods were fixed after some changes on CodeProject.

4 April 2013 (v1.0.3)

Logins have failed recently because of some updates on CodeProject. Fixed.

Random strings were appended to the urls to force the WebBrowser to reload cached pages.

17 October 2012 (v1.0.2)

New codes to remember last browsed path

A small change in extractMemberId() function

"Open with" support(You can use "Open with" menu or drag a cpa file and drop it on icon of the program.)

A unique file header to validate CPA (CodeProject Article) files(Because of that old cpa files cannot be opened with this version.)

5 October 2012 (v1.0.1)

"ctl00" became "ctl01" on the login page of codeproject. So a new function (getElementId()) was written to get IDs of elements using Regex class and this function was used instead of all old constants that will be able to be changed by codeproject in future.

Comments and Discussions

There doesn't seem to be a "Language Dropdown", a "'Var' Button", or a panel for uploading files. What's up with that--and how do I deal with that--especially if I want to work on an article offline? (I have version 1.0.4.0)

In both Build (Debug) and Publish and Install modes it gets stuck at 'Connected, Loggin in...'
I've tried stepping through in debug mode with break points at 'form load' and 'click login logout' methods, nothing obvious goes wrong, it just gets stuck whilst, presumably, waiting for a response from the server. I assume there is no time-out, I didn't see one? I do not get any kind of failed message.

It is clearly 'Connecting' successfully (I think) otherwise it would never reach 'Connected, Loggin in...'.
I've checked the firewall, Norton, and both the VS hosted and the installed app are approved / allowed to make network connections.

I'm using VS2012 Express on Windows 8 Desktop.
Any ideas what else I can try?

I have just tried it and couldn't see any problem, it is working.
Webbrowser control which is used in the program is based on internet explorer. So try to check IE.
Or in CPExtractor.cs there is a try-catch statement at line 171. Modify it to see whether there is any error:

Turned out to be the remnants of McAfee which was pre-installed on my machine at purchase but was supplanted by Norton within hours of receipt.
Somehow a product that had been uninstalled was preventing Java from running in IE but not posing a problem in FF.

Thanks for the great tool which is making writing interesting articles much easier than it used to be. I'm in the middle of a particularly ambitious one and having a few issues.
I get a lock up when trying to format large sections of code by highlighting and then changing the Heading level to Formatted. Is there a known limit on how many lines this can cope with? I have a very powerful PC so it's not a local resource limit.
Is there a better/recommended way of getting ~1000 lines of source formatted within the editor that will not lock up?

"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)

That's the error I get when I try and run the editor.
I've tried running in compatability mode (XP SP3, Vista SP2, Win 7) to no avail.
I've tried running the supplied exe directly and built it from the source on my PC and installed it as an app.
I've tried debugging but cannot work out where the issue is arising, it doesn't even seem to execute the code line that includes the error text (but this probably reveals only my misunderstandings).

Also, and this may be illuminating...
If I try to create a document in offline mode it works but I cannot edit it, by which I mean the editing controls don't appear and there are no scroll bars, I can just read the CP template text (ot at least the part that's visible without scrolling...).

I am wondering if the CKEditor is the problem.
If I load the CKEditor demo (http://ckeditor.com/demo[^]) into FF then it doesn't work until I allow Scripts (NoScript). If I load it into IE it just doesn''t work and I can't figure out how to let it work, so assuming the WebBrowser object is exactly what IE uses then I think I can understand why it doesn't work.

I could simply try downloading and replacing CKEditor wit the latest version but you've stripped it down and modified it.
I am using Win 8 / IE 10 and VS Express 2012 for Desktop.