Click here to Skip to main content
13,803,154 members
Click here to Skip to main content
Add your own
alternative version


124 bookmarked
Posted 1 Oct 2012
Licenced CPOL

Offline Article Editor For CodeProject

, 15 Dec 2013
Rate this:
Please Sign up or sign in to vote.
An offline wysiwyg editor to backup, edit or create new articles for CodeProject.

Editorial Note

Having trouble writing or posting articles? These articles aim to gather together tips and tricks from authors and mentors to help you write great articles.



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. 

Screenshot of the main window. Browsing for an article to edit
(Click on the images to view the full sized images in a new window.)


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:

class Example
    private Action after_MyThreadFinished;
    private Form invoker;

    public Example(Action after_MyThreadFinished, Form invoker)
        this.after_MyThreadFinished = after_MyThreadFinished;
        this.invoker = invoker;

    public void doSomeWorksAsynchronously()
        new Thread(() =>
            // some codes that take long time...

            if (after_MyThreadFinished != null)

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. 


private void button1_Click(object sender, EventArgs e)
    Action myAction = new Action(() =>
        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 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:

// Original code: B.preview.setAttribute('src',s.$.src);
// Modified for CP Article Editor
// The modification has been made to convert a relative image src to an
// absolute src in preview window.
// begin
if(s.$.src.substring(0,7)=='http://' || s.$.src.substring(0,8)=='https://')
    var kok=(document.getElementsByTagName('base')[0]==null?'**biseyyapma**':
    var verilenAdres=C;
    var tamAdres=kok+C;
// end

// Original code: --
// Modified for CP Article Editor
// The modification has been made to convert an absolute image src to a relative src.
// begin
// end

// Original code:'cke-saved-src',D.getValue()); C.setAttribute('src',D.getValue());
// Modified for CP Article Editor
// The modification has been made to convert a relative image src to an absolute src.
// begin
var verilenAdres=D.getValue();
if(verilenAdres.substring(0,7)=='http://' || verilenAdres.substring(0,8)=='https://')
    var kok=(document.getElementsByTagName('base')[0]==null?'**biseyyapma**':
    var tamAdres=(verilenAdres.indexOf(kok)<0?kok+verilenAdres:verilenAdres)'cke-saved-src',tamAdres);
// end

Used configurations:

fullPage        : false  // We are not editing a full page
language        : 'en'   // I removed all other language files to decrease the size.
resize_enabled  : false  // Prevent resizing the editor.
uiColor         : '#CCC' // Grey
tabSpaces       : 4      // Each tab character is replaced with 4 spaces.
contentsCss     : 'CodeProject.css'  // CSS stylesheet file of codeproject template.
removePlugins   : 'contextmenu,liststyle,tabletools' // For hiding ckeditor's context menu
docType         : '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"' +
                  '"">' // Document type of CodeProject.

Accessing And Modifying Elements Of An Html Document

I used a WebBrowser to login and extract required data. Here are some important methods.

Reading an attribute of an element:


Changing an attribute of an element:

webBrowser.Document.GetElementById("IdOfTheElement").SetAttribute("attribute", "new value");

Calling a javascript function that is inside a WebBrowser object from c#:

object[] args = new object[] { ... };
object returned = webBrowser.Document.InvokeScript("functionName", args);

Downloading Files From A Website

There is a very simple method for downloading files from a website. I used that method to download images related with an article.

WebClient webClient = new WebClient();
webClient.DownloadFile("", "C:\file.extension");

Disabling Click Sound In A WebBrowser

There isn't a property to disable the click sound in a web browser. But there is a way to do that using CoInternetSetFeatureEnabled API:

static class ClickSoundDisabler
    // ---------------------------------------------------
    //  CodeProjectArticleEditor > ClickSoundDisabler.cs
    // ---------------------------------------------------
    //  CodeProject Article Editor
    //  Huseyin Atasoy
    //  September 2012
    // ---------------------------------------------------

    private const int FEATURE_DISABLE_NAVIGATION_SOUNDS = 21;

    private const int SET_FEATURE_ON_PROCESS = 0x00000002;

    [return: MarshalAs(UnmanagedType.Error)]
    private static extern int CoInternetSetFeatureEnabled(int FeatureEntry,
        [MarshalAs(UnmanagedType.U4)] int dwFlags, bool fEnable);

    public static void disableClickSound()
                                        SET_FEATURE_ON_PROCESS, true);


This is the main window of the program:

Codeproject article editor main window

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: 

Welcome after login

article list

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

Informations about selected article

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

New article

Transferring Articles To CodeProject's Online Editor

  1. 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.)
  2. Open codeproject online editor.
  3. Click on "HTML" button to switch to HTML mode:
  4. Paste your contents. (CTRL+V) 
  5. 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#.


  • 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.
  • 1 October 2012 (v1.0.0)
    • First release.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Huseyin Atasoy
Turkey Turkey
I am interested in artificial intelligence, signal processing, electronics, robotics and internet/network technologies.

A few of my works:
KANO (Real-time Optical Mark Recognition)
Real-time object recognition
Real-time facial expression recognition

My blog

You may also be interested in...

Comments and Discussions

GeneralRe: My vote of 4 Pin
Huseyin Atasoy6-Oct-12 5:01
memberHuseyin Atasoy6-Oct-12 5:01 
GeneralMy vote of 5 Pin
fredatcodeproject5-Oct-12 10:12
professionalfredatcodeproject5-Oct-12 10:12 
GeneralRe: My vote of 5 Pin
Huseyin Atasoy6-Oct-12 4:59
memberHuseyin Atasoy6-Oct-12 4:59 
GeneralMy vote of 4 Pin
StianSandberg5-Oct-12 2:42
professionalStianSandberg5-Oct-12 2:42 
GeneralRe: My vote of 4 Pin
Huseyin Atasoy5-Oct-12 4:43
memberHuseyin Atasoy5-Oct-12 4:43 
GeneralRe: My vote of 4 Pin
Huseyin Atasoy17-Oct-12 0:43
memberHuseyin Atasoy17-Oct-12 0:43 
GeneralSounds Good! Pin
Shemeer NS5-Oct-12 0:42
memberShemeer NS5-Oct-12 0:42 
GeneralRe: Sounds Good! Pin
Huseyin Atasoy5-Oct-12 4:16
memberHuseyin Atasoy5-Oct-12 4:16 
GeneralMy vote of 5 Pin
LoveJenny5-Oct-12 0:07
memberLoveJenny5-Oct-12 0:07 
GeneralRe: My vote of 5 Pin
Huseyin Atasoy5-Oct-12 4:47
memberHuseyin Atasoy5-Oct-12 4:47 
GeneralMy vote of 4 Pin
César de Souza4-Oct-12 5:15
professionalCésar de Souza4-Oct-12 5:15 
GeneralRe: My vote of 4 Pin
Huseyin Atasoy4-Oct-12 6:18
memberHuseyin Atasoy4-Oct-12 6:18 
GeneralRe: My vote of 4 Pin
César de Souza4-Oct-12 6:34
professionalCésar de Souza4-Oct-12 6:34 
GeneralRe: My vote of 4 Pin
Huseyin Atasoy4-Oct-12 8:37
memberHuseyin Atasoy4-Oct-12 8:37 
GeneralMy vote of 5 PinPopular
Kenneth Haugland4-Oct-12 5:00
professionalKenneth Haugland4-Oct-12 5:00 
GeneralRe: My vote of 5 Pin
Huseyin Atasoy4-Oct-12 6:00
memberHuseyin Atasoy4-Oct-12 6:00 
GeneralMy vote of 5 PinPopular
Akram El Assas3-Oct-12 11:28
memberAkram El Assas3-Oct-12 11:28 
GeneralRe: My vote of 5 Pin
Huseyin Atasoy4-Oct-12 2:09
memberHuseyin Atasoy4-Oct-12 2:09 
GeneralMy vote of 5 PinPopular
bbirajdar2-Oct-12 7:54
memberbbirajdar2-Oct-12 7:54 
GeneralRe: My vote of 5 Pin
Huseyin Atasoy2-Oct-12 9:37
memberHuseyin Atasoy2-Oct-12 9:37 
GeneralRe: My vote of 5 Pin
bbirajdar6-Nov-12 19:30
memberbbirajdar6-Nov-12 19:30 
GeneralRe: My vote of 5 Pin
Huseyin Atasoy6-Nov-12 19:54
memberHuseyin Atasoy6-Nov-12 19:54 
GeneralRe: My vote of 5 Pin
bbirajdar6-Nov-12 21:07
memberbbirajdar6-Nov-12 21:07 
GeneralRe: My vote of 5 Pin
Huseyin Atasoy7-Nov-12 0:45
memberHuseyin Atasoy7-Nov-12 0:45 
GeneralMy vote of 5 Pin
Burak Ozdiken1-Oct-12 4:17
memberBurak Ozdiken1-Oct-12 4:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.181215.1 | Last Updated 15 Dec 2013
Article Copyright 2012 by Huseyin Atasoy
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid