Programming

Using FCKEditor in ASP.NET 3.5

FCKEditor is a text editor that you can use in a web page. It has many more options than the text input boxes in HTML. This is a WYSIWYG editor and resembles desktop applications like Microsoft Word.

It supports multiple languages, but if you want to use it in an ASP.NET site, the ASP.NET control for it is required. The problem here is that the documentation doesn’t fully explain how to use it in an ASP.NET 3.5 page.

Setting Up FCKEditor

You need to download the FCKEditor code, currently at version 2.6.6 and then the ASP.NET control to work with it. Open the ASP.NET page and place the following code below the <% Page Language … %> section to register the control:

<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>

To display an FCKEditor text box, place the following on the page:

<FCKeditorV2:FCKeditor ID="FCKeditor1" BasePath="~/fckeditor/" runat="server" Height="400" Width="800"></FCKeditorV2:FCKeditor>

The following control should then appear on your page. There are many options to customize the editor which depends on the application that its being used in.

Editing Text With FCKEditor

You can download FCKEditor at http://ckeditor.com/.

Calculating the Date from Exported PostgreSQL Table

When exporting a PostgreSQL database to another database server, such as MySQL or MS SQL Server, the date field will appear as a number if it is saved as an Excel sheet. After spending some time trying to determine what the number means, I found that it seems to represent the number of days from January 1, 1900.

The problem is that when I test the date with the C# code below, the actual date in the database is off by 2 days. This may be the result of the original PHP application not calculating the date correctly from the Postges database. I doubt that Postgres would have the first entry of the date field starting on January 3, 1900.


int iDays = 39970;          // number of days since January 1, 1900

DateTime StartTime = new DateTime (1900, 1, 1);
DateTime EndTime = StartTime.AddDays (iDays);

Console.WriteLine (EndTime.ToString ());

Using MySQL on Another Server

Many web servers have a database server on the same machine. A problem with this type of configuration is that it puts too much of a load on the server and overall performance can be poor with a high traffic web site. Database servers work best when they are on their own computer apart from the web server. The database can then use all of the computer’s resources to run more efficiently.

Finding the hosts File

Accessing a database such as MySQL on another server requires the use of the hosts file. This is used to connect to the database server by redirecting a hostname to the server’s IP. On Windows, you can find hosts in the operating system directory in the system32\drivers\etc\ folder. If your not sure where it is, use the file search function in your operating system.

In the hosts file, move to the bottom and enter the IP of the database server and hostname that you will use in your code to use the database. The following example shows the IP of the database server (74.208.28.228) and the hostname that is defined as mysql.database.

74.208.28.228    mysql.database

Connecting with PHP

An example of connecting with PHP:

$link = mysql_connect ('mysql.database', 'mysql_user', 'mysql_password');

A user account in MySQL to access the database needs to be created. You can’t use the root account when connecting to another server.

Once connected, you can perform functions on the database just like as if it was a local server on your computer. This procedure can also be used to connect to other database servers such as Microsoft SQL Server and PostgreSQL.

Making Sure You Have the Right Stuff

Anyone can learn programming from reading a couple of books on the subject, but it takes more than this to work as a software engineer. On the IndianGeek blog, Sijin Joseph created the Programming Competency Matrix that shows what a programmer needs to know and how knowledgeable they are at different levels (starting at level 0 of course).

The table is useful for knowing where you would stand when applying for a job at a software company. Not everything listed there would be relevant for most programmers, but it gives a broad overview of what a software builder should be familiar with.

Free eBook: Illustrated C# 2008

 

You can learn C# for free with a free eBook from redgate. They are offering Illustrated C# 2008 for download on their web site. Amazon sells the book for $29.69 so its a great value if you don’t mind reading electronic books.

Illustrated C# 2008 takes a different approach to teaching programming. There are many visual examples which accelerate the learning process. Its a good system for people who don’t like learning by reading lots of text.

The book is good for beginning programmers and also people who would like to learn a new language. Existing C# programmers could also benefit by learning a few new things here, especially those who are updating their knowledge from an earlier C# version.

If you find the book useful, order a printed version from Amazon or download it for the Kindle.