Creating news site heading like in Daylife.com Covers

Creating news site heading like in Daylife.com Covers

Tuesday, January 16, 2007 @ 15:48
Skip to: Comments | Comment form

A few days ago I stumbled upon an interesting news site called Daylife. Its front page (Covers) is something like an internet/TV hybrid, with its flash intro page that displays most recent news. To say the least, I am a fan of Flash, as of JavaScript and other technologies, but I think that the same (or almost the same) “vow” effect could be done with XHTML/CSS combination as well.

This front page is loading very slowly, and I think it would be better that they considered some XHTML/CSS/AJAX stuff, that would be faster.

In this article I will show you how to create this kind of front page using only XHTML/CSS. As I am not the JavaScript/AJAX expert (yet:), if anyone else would like to expand this article furthermore (to create that expanding effect), please do so.

Creating news site heading like in Daylife.com Covers

The code


<div id="container">

	<div id="image-container">

		<div id="news-image"><img src="great-sun-burst.jpg" alt="Great sun burst" /></div>

		<a href="#" title="Great sun burst!" id="link">
			<span id="heading">Great sun burst!</span>
			<span id="date">January 13, 2007</span>
			<span id="author">Photo by <strong>thesaint</strong> from <strong>SXC</strong></span>
			<span id="show-story">Click to see this story</span>
		</a>		

	</div>

</div>

Okay, let’s start. First, we will create a #image-container DIV, with exact size of the image that will serve as a container for the image and text. Because we created this container, we can easily manipulate and move the container anywhere on the page. For the purpose of this article, the container will be positioned 50px from top and left margins.

Now it’s time to create the image and the text. Because this kind of heading will be commonly used on the large news sites and with Content Management Systems (CMS) we would have the exact values already. We created a container that is 750px long and 500px wide (the size of our image). We wanted heading, date and author to be placed on the center of the image. No problem.

And now for a little explaining. We created a DIV for the image called #news-image. This is because of IE. If you remove it, everything looks fine in Firefox, but IE cripples the page. It looks awful (don’t bother to look :) . Important and tricky part comes here. To create a validated page, we used spans inside a link, and each SPAN has its own ID, to which we will apply some styling, later in the process. The text will be displayed inside a link, so the whole area is clickable (like in navigation).

Important note: If you have more than one heading (with picture) like this one, you should use classes instead of IDs, to create a validated page.

CSS


#image-container {
	position:relative;
	width:750px;
	height:500px;
	margin:50px 0 0 50px;
}

First, we will style the image container. This is not much of a styling, but it is important that we define two things. The container must be positioned relatively, and width exact width and height. Let’s style the links now.


a {
	display:block;
	position:absolute;
	top:50%;
	margin-top:-58px;
	padding:20px;
	width:710px;
	background:#000;
	color:#fff;
	text-decoration:none;
	text-align:center;
	opacity:.5;
	filter:Alpha(Opacity=50);
}
a:hover {
	opacity:.75;
	filter:Alpha(Opacity=75);
}

The link will be displayed as block, and positioned absolutely within the container. While we positioned the container relatively, we can now position the link area absolutely with top:50%; and margin-top:-63px;. Margin-top value is here because we wanted our link area positioned somewhere in the middle of the image. With top:50%; we said to the browser to position the top margin of the link area exactly 50% from the top, and with negative top margin of the link itself, we positioned the whole area approximately to the horizontal center of the image.

How we come up with 63px, you may ask? This is the sum of the sizes of all the text in the link area. The next few rules are common, and the last two rules are here to create an “opacity look” of the link, that will change when we come over with the mouse pointer. We used opacity:.5; for Firefox, and the filter:Alpha(Opacity=50); for Internet explorer users.


a span {
	display:block;
	margin:0;
}
#heading {
	font-size:4em;
}
#date {
	font-size:1.5em;
}
#author, #show-story {
	font-size:.8em;
	font-family:Verdana, Arial, Helvetica, sans-serif;
	text-transform:uppercase;
	padding-top:5px;
}

With the next set of rules, we stylized the text. We used a span { display:block; margin:0; } to display all spans as blocks, and to remove the margin. The next few rules for #heading, #date, #author, #show-story are here to stylize the text.

The last thing we want to do is to display the author of the image (or article) and the text “Click to see this story” when the mouse goes over a link. To do that, we used this CSS.


a span#show-story { display:none; }
a:hover span#show-story { display:block; }

http://www.emanuelblagonic.com/2007/01/16/creating-news-site-heading-like-in-daylifecom-covers/

a:hover span#author { display:none; }

With this set of rules, #show-story SPAN will not be visible when the mouse is not over the link, and the other SPAN #author will not be visible when the mouse is over the link. Easy and simple.

Hope you enjoyed reading this article.

The example

Creating news site heading like in Daylife.com “Covers” – Take a look at the example

Đàm phán với thương nhân Mỹ

Kỳ 1: Kỹ năng làm quen
Khác với phần đông thương nhân Châu Á và thương nhân một số quốc gia khác, người Mỹ không e ngại phải làm việc với người lạ. Chính vì vậy, các DN hoàn toàn có thể tự làm quen với thương nhân Mỹ thông qua thư từ, email hay điện thoại trực tiếp.

Tuy nhiên, nếu DN có thể tìm được người giới thiệu, hay tìm cơ hội gặp gỡ với bạn hàng tại các hội chợ, triển lãm thì sẽ rút ngắn được thời gian tìm hiểu nhau hơn. Còn nếu quyết định tự làm quen, DN nên chuẩn bị đầy đủ những tài liệu về tư cách pháp nhân, khả năng kinh doanh của mình để chiếm được lòng tin của đối tác. Dù làm quen theo phương pháp nào, cũng chỉ nên đến gặp đối tác khi đã được hẹn trước. Những cuộc thăm viếng bất ngờ có thể bị coi là rất bất lịch sự tại nơi này. Sau đây là một số kỹ năng giúp DN đàm phán với các thương nhân Mỹ

Kỹ năng giao tiếp

Người Mỹ nổi tiếng là những người có tác phong giao tiếp cởi mở, thân thiện. Ngôn ngữ chủ yếu để giao dịch ở đây là tiếng Anh. Khi gặp nhau, tùy theo thời điểm mà chúng ta có thể dùng [I]“good morning” hay “good afternoon”…, có thể kèm theo cúi đầu hoặc bắt tay nhẹ. Khác với người Pháp, người Mỹ không hay bắt tay, nếu có cũng không không kéo dài. Những cử chỉ khác như vỗ vai, ôm hôn,… không phổ biến ở Mỹ.

Người Mỹ cũng không cầu kỳ trong cách ăn mặc, đặc biệt là các doanh nhân. Hình ảnh Bill Gates, người giàu nhất thế giới, thường xuất hiện trước công chúng trong bộ trang phục quần Jean và áo chui đầu, có thể coi như phong cách điển hình của Mỹ.

Người Mỹ rất coi trọng công việc, đối với họ “business is business” nên họ coi trọng trước hết là hiệu quả công việc. Vì vậy, việc tặng quà hay tổ chức các bữa tiệc tiếp đón không thật sự cần thiết. Người Mỹ không coi trọng việc tặng quà. Hơn nữa, luật pháp nước Mỹ quy định rất chặt chẽ về việc chống tham nhũng nên các thương nhân không được trao và nhận những món quà đắt tiền. Vì vậy, khi gặp nhau các bên chỉ nên chuẩn bị những món quà mang tính lưu niệm có logo của Cty.

Kỹ năng thương lượng

Tốc độ – vấn đề đầu tiên cần lưu tâm ở Mỹ. Điều cần lưu ý đầu tiên khi làm việc với người Mỹ có lẽ là tốc độ trong công cuộc làm ăn của họ. Người Mỹ có khuynh hướng định đoạt mau chóng mọi chuyện. Nếu họ không bán ngay được hàng cho bạn, họ sẽ bỏ đi bán cho người khác. Thông thường, nhịp độ đàm phán được quyết định bởi bên có ưu thế. Vì vậy, khi giao dịch với thương nhân Mỹ, chắc chắn chúng ta sẽ phải tăng tốc độ. Câu nói cửa miệng của người Mỹ là “Make it snappy!” (Nhanh lên!), “Jump to it” (Nhào vô!) “What are we waiting for” (Còn chờ gì nữa?). Với người Mỹ, phí thời giờ tức là phí đời sống.

Quy mô to lớn của các cuộc giao dịch. Nhà đàm phán nên chuẩn bị những đơn chào hàng với số lượng lớn hơn nhiều so với các thương vụ làm ăn với các DN ASEAN hay EU. Tuy nhiên cần lường trước năng lực của mình khi đưa ra đơn chào hàng vì một khi đã đưa ra, chúng ta sẽ rất khó có khả năng thay đổi.

Trong giao tiếp, người Mỹ ưa thích sự thẳng thắn và phô trương. Một trong những nguyên nhân đầu tiên dẫn đến nhận xét này là người Mỹ thường có xu hướng nói to, thích nhìn thẳng vào người đối diện và có thái độ đòi hỏi quyền lợi một cách công khai. Họ luôn luôn thúc đẩy cuộc thương lượng đến chỗ kết thúc một cách mau chóng nhất. Rất tự tin và phô trương, họ dễ dàng tìm cách ép buộc bạn chấp nhận điều họ đề nghị. Điều đầu tiên là họ muốn gây ấn tượng là họ rất hùng mạnh bằng các con số về quy mô của Cty trên thị trường, kim ngạch mua bán hay số nhân công. Họ muốn làm bạn có cảm giác được giao dịch với họ là quyền lợi lớn nhất của bạn. Người Mỹ có thể gây cho ta cảm tưởng là họ không thận trọng lắm. Nhưng trên thực tế, họ có đủ sức để chịu đựng vài ba thất bại, các giao dịch của họ đã được chuẩn bị hết sức kỹ lưỡng để bảo vệ tối đa quyền lợi của mình vì vâỵ, bạn đừng mất tinh thần vì vẻ bề ngoài của họ.

Hoàng Ngọc Ánh

Make Your Windows Xp Run Faster Than Never Before!

First of all this tips & tricks is courtsey not by me but i have found on on of the forum. I ahve tried this tricks and works very good

Most imp thing is thgat if anyone colund not follow and get problems or any type of damages by this tips anyhow……….. i’ll not be responsible

Her r the tips…………….

DISABLE INDEXING SERVICES
Indexing Services is a small little program that uses large amounts of RAM and can often make a computer endlessly loud and noisy. This system process indexes and updates lists of all the files that are on your computer. It does this so that when you do a search for something on your computer, it will search faster by scanning the index lists. If you don’t search your computer often, or even if you do search often, this system service is completely unnecessary. To disable do the following:

1. Go to Start
2. Click Settings
3. Click Control Panel
4. Double-click Add/Remove Programs
5. Click the Add/Remove Window Components
6. Uncheck the Indexing services
7. Click Next

OPTIMISE DISPLAY SETTINGS

Windows XP can look sexy but displaying all the visual items can waste system resources. To optimise:

1.Go to Start
2. Click Settings
3. Click Control Panel
4. Click System
5. Click Advanced tab
6. In the Performance tab click Settings
7. Leave only the following ticked:
- Show shadows under menus
- Show shadows under mouse pointer
- Show translucent selection rectangle
- Use drop shadows for icons labels on the desktop
- Use visual styles on windows and buttons

DISABLE PERFORMANCE COUNTERS

Windows XP has a performance monitor utility which monitors several areas of your PC’s performance. These utilities take up system resources so disabling is a good idea.

To disable:

1. download and install the Extensible Performance Counter List(http://www.microsoft.com/windows2000/remove404.mspx)
2.Then select each counter in turn in the ‘Extensible performance counters’ window and clear the ‘performance counters enabled’ checkbox at the bottom.button below.

SPEEDUP FOLDER BROWSING

You may have noticed that everytime you open my computer to browse folders that there is a slight delay. This is because Windows XP automatically searches for network files and printers everytime you open Windows Explorer. To fix this and to increase browsing significantly:

1. Open My Computer
2. Click on Tools menu
3. Click on Folder Options
4. Click on the View tab.
5. Uncheck the Automatically search for network folders and printers check box
6. Click Apply
7. Click Ok
8. Reboot your computer

IMPROVE MEMORY USAGE

Cacheman Improves the performance of your computer by optimizing the disk cache, memory and a number of other settings.

Once Installed:

1.Go to Show Wizard and select All
2.Run all the wizards by selecting Next or Finished until you are back to the main menu. Use the defaults unless you know exactly what you are doing.
3.Exit and Save Cacheman
4.Restart Windows

OPTIMISE YOUR INTERNET CONNECTION

There are lots of ways to do this but by far the easiest is to run TCP/IP Optimizer.

1. Download(www.speedguide.net/files/tcpoptimizer.exe) and install
2. Click the General Settings tab and select your Connection Speed (Kbps)
3. Click Network Adapter and choose the interface you use to connect to the Internet
4. Check Optimal Settings then Apply
5. Reboot

OPTIMISE YOUR PAGEFILE

If you give your pagefile a fixed size it saves the operating system from needing to resize the page file.

1. Right click on My Computer and select Properties
2. Select the Advanced tab
3. Under Performance choose the Settings button
4. Select the Advanced tab again and under Virtual Memory select Change
5. Highlight the drive containing your page file and make the initial Size of the file the same as the Maximum Size of the file.

Windows XP sizes the page file to about 1.5X the amount of actual physical memory by default. While this is good for systems with smaller amounts of memory (under 512MB) it is unlikely that a typical XP desktop system will ever need 1.5 X 512MB or more of virtual memory. If you have less than 512MB of memory, leave the page file at its default size. If you have 512MB or more, change the ratio to 1:1 page file size to physical memory size.

RUN BOOTVIS – IMPROVE BOOT TIMES download from(www.majorgeeks.com)
BootVis will significantly improve boot times

1. Download and Run
2. Select Trace
3. Select Next Boot and Driver Trace
4. A Trace Repetitions screen will appear, select Ok and Reboot
5. Upon reboot, BootVis will automatically start, analyze and log your system’s boot process. When it’s done, in the menu go to Trace and select Optimize System
6. Reboot.
7. When your machine has rebooted wait until you see the Optimizing System box appear. Be patient and wait for the process to complete

REMOVE THE DESKTOP PICTURE
Your desktop background consumes a fair amount of memory and can slow the loading time of your system. Removing it will improve performance.

1. Right click on Desktop and select Properties
2. Select the Desktop tab
3. In the Background window select None
4. Click Ok

REMOVE FONTS FOR SPEED

Fonts, especially TrueType fonts, use quite a bit of system resources. For optimal performance, trim your fonts down to just those that you need to use on a daily basis and fonts that applications may require.

1. Open Control Panel
2. Open Fonts folder
3. Move fonts you don’t need to a temporary directory (e.g. C:\FONTBKUP?) just in case you need or want to bring a few of them back. The more fonts you uninstall, the more system resources you will gain.

DISABLE UNNECESSARY SERVICES

Because Windows XP has to be all things to all people it has many services running that take up system resources that you will never need. Below is a list of services that can be disabled on most machines:

Alerter
Clipbook
Computer Browser
Distributed Link Tracking Client
Fast User Switching
Help and Support – (If you use Windows Help and Support leave this enabled)
Human Interface Access Devices
Indexing Service
IPSEC Services
Messenger
Netmeeting Remote Desktop Sharing (disabled for extra security)
Portable Media Serial Number
Remote Desktop Help Session Manager (disabled for extra security)
Remote Procedure Call Locator
Remote Registry (disabled for extra security)
Remote Registry Service
Secondary Logon
Routing & Remote Access (disabled for extra security)
Server
SSDP Discovery Service – (Unplug n’ Pray will disable this)
Telnet
TCP/IP NetBIOS Helper
Upload Manager
Universal Plug and Play Device Host
Windows Time
Wireless Zero Configuration (Do not disable if you use a wireless network)
Workstation
To disable these services:

Go to Start and then Run and type “services.msc”
Doubleclick on the service you want to change
Change the startup type to ‘Disable”

TURN OFF SYSTEM RESTORE

System Restore can be a useful if your computer is having problems, however storing all the restore points can literally take up Gigabytes of space on your hard drive. To turn off System Restore:

Open Control Panel
Click on Performance and Maintenance
Click on System
Click on the System Restore tab
Tick ‘Turn off System Restore on All Drives’
Click ‘Ok’

DEFRAGMENT YOUR PAGEFILE

Keeping your pagefile defragmented can provide a major performance boost. One of the best ways of doing this is to creat a separate partition on your hard drive just for your page file, so that it doesn’t get impacted by normal disk usage. Another way of keeping your pagefile defragmented is to run PageDefrag. This cool little app can be used to defrag your pagefile, and can also be set to defrag the pagefile everytime your PC starts. To install:

Download(www.sysinternals.com) and Run PageDefrag
Tick “Defrag at next Reboot”,
Click “Ok”
Reboot

SPEEDUP FOLDER ACCESS – DISABLE LAST ACCESS UPDATE

If you have a lot of folders and subdirectories on your computer, when you access a directory XP wastes a lot of time updating the time stamp showing the last access time for that directory and for ALL sub directories. To stop XP doing this you need to edit the registry. If you are uncomfortable doing this then please do not attempt.

Go to Start and then Run and type “regedit”
Click through the file system until you get to “HKEY_LOCAL_MACHINE\System\Cur rentControlSet\Control\FileSys tem”
Right-click in a blank area of the window on the right and select ‘DWORD Value’
Create a new DWORD Value called ‘NtfsDisableLastAccessUpdate’
Then Right click on the new value and select ‘Modify’
Change the Value Data to ‘1′
Click ‘OK’

DISABLE SYSTEM SOUNDS

Surprisingly, the beeps that your computer makes for various system sounds can slow it down, particularly at startup and shut-down. To fix this turn off the system sounds:

Open Control Panel
Click Sounds and Audio Devices
Check Place volume icon in taskbar
Click Sounds Tab
Choose “No Sounds” for the Sound Scheme
Click “No”
Click “Apply”
Click “OK”

IMPROVE BOOT TIMES
A great new feature in Microsoft Windows XP is the ability to do a boot defragment. This places all boot files next to each other on the disk to allow for faster booting. By default this option in enables but on some builds it is not so below is how to turn it on.

Go to Start Menu and Click Run
Type in “Regedit” then click ok
Find “HKEY_LOCAL_MACHINE\SOFTWARE\M icrosoft\Dfrg\BootOpt imizeFunction”
Select “Enable” from the list on the right
Right on it and select “Modify”
Change the value to “Y to enable”
Reboot

IMPROVE SWAPFILE PERFORMANCE

If you have more than 256MB of RAM this tweak will considerably improve your performance. It basically makes sure that your PC uses every last drop of memory (faster than swap file) before it starts using the swap file.

Go to Start then Run
Type “msconfig.exe” then ok
Click on the System.ini tab
Expand the 386enh tab by clicking on the plus sign
Click on new then in the blank box type”ConservativeSwapfileUsage =1″
Click OK
Restart PC

MAKE YOUR MENUS LOAD FASTER

This is one of my favourite tweaks as it makes a huge difference to how fast your machine will ‘feel’. What this tweak does is remove the slight delay between clicking on a menu and XP displaying the menu.

Go to Start then Run
Type ‘Regedit’ then click ‘Ok’
Find “HKEY_CURRENT_USER\Control Panel\Desktop\”
Select “MenuShowDelay”
Right click and select “Modify’
Reduce the number to around “100″
This is the delay time before a menu is opened. You can set it to “0″ but it can make windows really hard to use as menus will open if you just look at them – well move your mouse over them anyway. I tend to go for anywhere between 50-150 depending on my mood

MAKE PROGRAMS LOAD FASTER

This little tweak tends to work for most programs. If your program doesn’t load properly just undo the change. For any program:

Right-click on the icon/shortcut you use to launch the program
Select properties
In the ‘target’ box, add ‘ /prefetch:1′ at the end of the line.
Click “Ok”
Voila – your programs will now load faster.

IMPROVE XP SHUTDOWN SPEED

This tweak reduces the time XP waits before automatically closing any running programs when you give it the command to shutdown.

Go to Start then select Run
Type ‘Regedit’ and click ok
Find ‘HKEY_CURRENT_USER\Control Panel\Desktop\’
Select ‘WaitToKillAppTimeout’
Right click and select ‘Modify’
Change the value to ‘1000′
Click ‘OK’
Now select ‘HungAppTimeout’
Right click and select ‘Modify’
Change the value to ‘1000′
Click ‘OK’
Now find ‘HKEY_USERS\.DEFAULT\Control Panel\Desktop’
Select ‘WaitToKillAppTimeout’
Right click and select ‘Modify’
Change the value to ‘1000′
Click ‘OK’
Now find ‘HKEY_LOCAL_MACHINE\System\Cur rentControlSet\Control\’
Select ‘WaitToKillServiceTimeout’
Right click and select ‘Modify’
Change the value to ‘1000′
Click ‘OK’

SPEED UP BOOT TIMES I

This tweak works by creating a batch file to clear the temp and history folders everytime you shutdown so that your PC doesn’t waste time checking these folders the next time it boots. It’s quite simple to implement:

1. Open Notepad and create a new file with the following entries:

RD /S /q “C:\Documents and Settings\”UserName without quotes”\Local Settings\History”
RD /S /q “C:\Documents and Settings\Default User\Local Settings\History”
RD /S /q “D:\Temp\” <–”Deletes temp folder, type in the location of your temp folder”

2. Save the new as anything you like but it has to be a ‘.bat’ file e.g. fastboot.bat or deltemp.bat

3. Click ‘Start’ then ‘Run’

4. Type in ‘gpedit.msc’ and hit ‘ok’

5. Click on ‘Computer Configuration’ then ‘Windows Settings’

6. Double-click on ‘Scripts’ and then on ‘Shutdown’

7. Click ‘Add’ and find the batch file that you created and then press ‘Ok’

SPEED UP BOOT TIMES II

When your PC starts it usually looks for any bootable media in any floppy or cd-rom drives you have installed before it gets around to loading the Operating System from the HDD. This can waste valuable time. To fix this we need to make some changes to the Bios.

1. To enter the bios you usually press ‘F2′ or ‘delete’ when your PC starts

2. Navigate to the ‘Boot’ menu

3. Select ‘Boot Sequence’

4. Then either move your Hard drive to the top position or set it as the ‘First Device’

5. Press the ‘Escape’ key to leave the bios. Don’t forget to save your settings before exiting

Note: Once this change has been made, you won’t be able to boot from a floppy disc or a CD-rom. If for some strange reason you need to do this in the future, just go back into your bios, repeat the steps above and put your floppy or CD-rom back as the ‘First Device’

SPEED UP BOOT TIMES III

When your computer boots up it usually has to check with the network to see what IP addresses are free and then it grabs one of these. By configuring a manually assigned IP address your boot time will improve. To do this do the following:

1. Click on ‘Start’ and then ”Connect To/Show All Connections’

2. Right-click your network adapter card and click ‘Properties’.

3. On the ‘General’ tab, select ‘TCP/IP’ in the list of services and click ‘Properties’

4.I n the TCP/IP properties, click ‘Use the following address’ and enter an IP address for your PC. If you are using a router this is usually 192.168.0.xx or 192.168.1.xx. If you are not sure what address you could check with your ISP or go to ‘Start/run’ and type ‘cmd’ and then ‘ipconfig/all’. This will show your current IP settings which you will need to copy.

5. Enter the correct details for ‘Subnet mask’, ‘Default gateway’ and ‘DNS Server’. Again if you are not sure what figures to enter use ‘ipconfig/all’ as in stage 4.

FREE UP MEMORY
I found this useful app via FixMyXP. ClearMem Is an Excellent Tool for speeding up your XP Computer (especially if your system has been on for awhile and you have a lot of applications open). What it does, is it Forces pages out of physical memory and reduces the size of running processes if working sets to a minimum. When you run this tool, the system pauses because of excessive high-priority activity associated with trimming the working sets. To run this tool, your paging file must be at least as large as physical memory. To Check your Paging File:

1. Go to your control panel, then click on ‘System’, then go to the ‘Advanced’ Tab, and Under ‘Performance’ click ‘Settings’ then the ‘Advanced’ Tab

2. On the Bottom you should see ‘Virtual Memory’ and a value. This is the value that must be at least as large as how much memory is in your system.

3. If the Virtual Memory Value is smaller than your system memory, click Change and change the Min Virtual Memory to a number that is greater than your total system memory, then click ‘Set’ and Reboot.

4. Once you have rebooted install ClearMem

ENSURE XP IS USING DMA MODE

XP enables DMA for Hard-Drives and CD-Roms by default on most ATA or ATAPI (IDE) devices. However, sometimes computers switch to PIO mode which is slower for data transfer – a typical reason is because of a virus. To ensure that your machine is using DMA:

1. Open ‘Device Manager’

2. Double-click ‘IDE ATA/ATAPI Controllers’

3. Right-click ‘Primary Channel’ and select ‘Properties’ and then ‘Advanced Settings’

4. In the ‘Current Transfer Mode’ drop-down box, select ‘DMA if Available’ if the current setting is ‘PIO Only’

ADD CORRECT NETWORK CARD SETTINGS

Some machines suffer from jerky graphics or high CPU usage even when a machine is idle. A possible solution for this, which, can also can help network performance is to:

1. RightClick ‘My Computer’

2. Select ‘Manage’

3. Click on ‘Device Manager’

4. DoubleClick your network adaptor under ‘Network Adapters’

5. In the new window, select the ‘Advanced’ tab

6. Select ‘Connection Type’ and select the correct type for your card and then Reboot

REMOVE ANNOYING DELETE CONFIRMATION MESSAGES

Although not strictly a performance tweak I love this fix as it makes my machine ‘feel’ faster. I hate the annoying ‘are you sure?’ messages that XP displays, especially if I have to use a laptop touchpad to close them. To remove these messages:

1. Right-click on the ‘Recycle Bin’ on the desktop and then click ‘Properties’

2. Clear the ‘Display Delete Confirmation Dialog’ check box and click ‘Ok’

If you do accidently delete a file don’t worry as all is not lost. Just go to your Recycle Bin and ‘Restore’ the file.

DISABLE PREFETCH ON LOW MEMORY SYSTEMS

Prefetch is designed to speed up program launching by preloading programs into memory – not a good idea is memory is in short supply, as it can make programs hang. To disable prefetch:

1. Click ‘Start’ then ‘Run’

2. Type in ‘Regedit’ then click ‘Ok’

3. Navigate to ‘HKEY_LOCAL_MACHINE\SYSTEM\Cur rentControlSet\Control\Session Manager\Memory Management\PrefetchParameters\ ‘

4. Right-click on “EnablePrefetcher” and set the value to ‘0′

5. Reboot.

Do at your own risk

Enjoy…. if u like plss post the thanks only

writing on wall for vertical job search engines?

Is it too early to forecast the demise of the vertical job search engines? Maybe. Maybe not. Here are some thoughts to consider:

  1. Indeed – If any vertical will survive on its own, these guys are it. They know the job board business better than their peers and have kept things focused and lean-and-mean from Day One. That said, the recent choice by investor New York Times to ally with Monster Worldwide doesn’t bode well for the current state of revenue generation for Indeed. Their PPC model, a la Google AdWords, is well done, but by the time enough job boards become advertisers (assuming a profitable number do become advertisers), the faucet of content may dry-up.
  2. Simply Hired – Born to be acquired and partying like its 1999. The gang at SH is very talented but their trial-and-error is reminiscent of the early days: resume blasting, untargeted banner ads (a job search for “marketing” in “Cleveland” gives me general ads for Dice, a healthcare job board and Oracle) and giveaway promos for a free HP Jordana, er, I mean iPhone. The Job-a-matic product is nice, but I have doubts the blogging masses will generate enough cash to make it worthwhile. Hell, I write for the Internet recruiting space and only have 2 job postings on my own board … and postings are only $5. Geesh!
  3. Jobster – The evolution of these cats reads like a horror story out of business school. Referral site then vertical job search engine then social network then layoffs then free-for-all and spending God-only-knows to partner exclusively with Facebook. Whew! At least $50 million buys a great roller coaster ride. I look at Jobster and see a site at this point just hoping to 1) drive a bunch of traffic, 2) get a lot of registered users and, most importantly, 3) pull a good number of employers into their database via free job postings, in return for becoming an appealing acquisition target. Maybe if someone like IAC buys Facebook, they’ll throw in Jobster for fun. Dating with your job search anyone?
  4. The periphery – Take a look at the second tier players in this space and there’s not much to be impressed about. Many are experiments, supporting sites to bigger ones, drowning without an acquisition lifesaver or, worse yet, none of the above. I think you’ll see a lot of death and destruction in the coming year.

It makes me sad. I hope I’m wrong. I’m a big fan of vertical search in general, but particularly for jobs. I think users prefer a single destination to search multiple boards and employers. And I still believe the idea can work in the right environment. Google Base is seeing improvement and traffic mammoth Yahoo! has a lot of potential integrating job content from around the Web.

However, the unfortunate reality may be that no matter how much the verticals provide a great service, pleasing the investors who have poured tens of millions into seeing big money probably are not all that pleased right about now.

That said, a majority of the primary verticals have told me to be on the lookout for enhancements that will “blow your mind.” We’ll see. Blowing away the revenue projections would probably be more important at this point.

(http://www.cheezhead.com/2007/03/13/writing-on-wall/)

Free: a Tactic, not a Business Model

Every time an economic bubble develops, many will tell you how “this time it’s different,” how “this time the rules have changed.” The lie of the Web 2.0 bubble is that free is the way to succeed in the new economy. That’s not true. The rules of economics have not changed. The best way to make money in the new economy, in the Web 2.0 economy, comes down to the same fundamental business model that has always existed: create something of value for people who will pay for it.

Josh Kopelman of Redeye VC notes the penny gap:

scaling from $5 to $50 million is not the toughest part of a new venture – it’s getting your users to pay you anything at all. The biggest gap in any venture is that between a service that is free and one that costs a penny.

Then he suggests that the existence of this hard-to-cross chasm means you should look for someone other than users to pay–advertisers perhaps.

However, the reason there’s a huge gap between people paying you nothing and people paying you something is because that’s where you go from hobby to business. Between zero revenue and positive revenue lies your business model. Going from zero pay to a penny is where you’ve discovered how to make money–and that’s what businesses are about. The penny gap separates the winners from the losers, economically speaking.

VC Fred Wilson wrote in defense of free in 2005: “free is a great way to make money. You just have to know how you are going to get paid for being free.”

That’s the key to having a business: getting paid, not whether you offer free samples in the morning newspaper to convince people your shampoo smells really great.

To be fair to these VCs, they’re not advocating doing everything without pay. They’re suggesting free as a tactic towards getting paid in other ways: through advertising, or by premium services (as in a freemium model), or maybe even through being acquired by a company with a large wallet. Free is only a tactic, though, not a business model.

Conflating the two misleads web application developers into thinking they don’t need to do the hard work of figuring out what’s really of value to users before they build and launch their online service. Who loses? Users, because we have to suffer through introduction after introduction of half-baked web apps that we’re not willing to pay for with our money or our attention.

( http://gigaom.com/2007/03/13/free-a-tactic-not-a-business-model/)

Rules for Good Program Design

If you are doing it twice, you are doing it wrong. Every piece of code should be designed only once. When setting to a new project, look for places to reuse your previous code. Allow old code to be modified to serve multiple purposes. As you work in any language, you should be building a large toolbox of subroutines that you can bring to bear on each new task.

Borrow code. When able, pick a programming language that is popular, so you can go download code that others have already created. Check around before you commit hours to writing code that someone else probably already wrote.

Make the computer do the work for you. Work to make any repetitive task into an automated one. Some tasks will actually take longer to accomplish when not done manually, but over time you will recoup those lost minutes when performing similar tasks.

Find short cuts. If you expect that you will type the same command over and over, make an alias for it that is one or two characters long. Use an editor that allow easy insertion of long variable and command names. Fewer keystrokes, even for fast typists, can save a lot of time.

Make code legible. Make variable names and procedure names long and clear. Usually variables should be nouns, procedures should be verbs, and procedures that return a value of importance should be nouns. This is a critical part of good internal documentation. The time saved in making short variable and procedure names will be lost many times over when trying to read the code later. Add comments that say why you are doing what you are doing, and make sure that your programs are clear enough about how you are doing it.

Find elegant solutions. Perhaps the hardest part of good programming is creating abstract data structures and programs that can handle any problem that is likely to be presented. Code that has exceptions for unusual requests are difficult to maintain and fail to scale well when those unusual requests become common tasks.

Test. Always test out changed code in many different situations. Consider how a change might affect other programs. Make all your tests automated, or you will not want to run them all the time.

There is no good writing, only good rewriting. Read over your code frequently to see how it can be improved. After a project has matured, a full rewrite will often sweep out all old bugs and accurately capture the evolved program requirements. Get other good programmers to read your code and offer suggestion. If you would be embarrassed to have your work critiqued, get busy rewriting it.

Founders at Work: Sabeer Bhatia, Hotmail

“Khi đó, chúng tôi đều đang có công việc riêng, và chúng thôi quyết định dành mọi thời gian cuối tuần và các buổi tối để phát triển sản phẩm. Rồi đến một thời điểm mà một trong hai chúng tôi phải bỏ việc để tập trung toàn bộ thời gian vào nó, nên tôi bảo Jack [Smith] “Tôi độc thân và không có gia đình. Sao anh không nghỉ việc để làm cái này và tôi sẽ đưa anh một nửa lương của tôi?” Ít nhất là anh ấy có thể nuôi gia đình mình. Tôi không cần nhiều tiền đến thế”. Bhatia và Smith cùng làm cho Apple vào thời điểm đó.

“Chúng tôi tìm đến các nhà đầu tư mạo hiểm và nhiều trong số họ không thích và nói: “Anh sẽ kiếm tiền kiểu gì nếu như anh cho người khác dùng miễn phí?” Chúng tôi nói sẽ thu thập được thông tin về phân bố tuổi của khách hàng, và chất lượng thông tin của từng khách hàng sẽ giúp chúng ta quảng cáo đến họ. Nhưng tất nhiên vào thời điểm đó thì quảng cáo vẫn chưa phải là mô hình doanh thu hiệu quả.”

“Nếu cái đó [Hotmail] giải quyết tốt các vấn đề của mình, nó cũng sẽ giải quyết các vấn đề của người khác nữa”.

“Anh phải nhận ra là vào những ngày đó chúng tôi chẳng có gì, chỉ đơn thuần là ý tưởng. Mỗi khi gõ cửa một nhà đầu tư, họ sẽ lắc đầu vì lý do này hay lý do khác, chẳng hạn như: “Các anh, các anh học gì ra?” Chúng tôi bảo họ là chúng tôi học về phần cứng. “Vậy tại sao anh phát triển phần mềm?”.

Một số còn nói, “Nhưng các anh quá trẻ. Các anh có kinh nghiệm quản lý không?”. “Không”, chúng tôi nói, “chúng tôi chỉ là hai gã trai trẻ; chúng tôi có một ý tưởng cực hay”.”

“Cộng đồng nhà đầu tư mạo hiểm quan hệ chằng chịt với nhau, anh không biết đâu.”

“Phải mất nhiều thời gian trước khi anh tạo đột phá đến một nhà quảng cáo và khiến họ trả tiền anh. Thực tế là, trong 3-4 tháng đầu chúng tôi quảng cáo giúp họ miễn phí”.

Bhatia kể về quá trình thương lượng để bán Hotmail cho Microsoft: “Vào tháng 8/1997, Microsoft liên hệ chúng tôi và nói: “Wow, [Hotmail] to thật đấy. Có thật là anh có 7 triệu người dùng không?” Họ biết là chúng tôi đang phát triển rất nhanh và họ muốn biết làm thế nào mà chúng tôi có thể phục vụ email cho 7 triệu người bởi vì họ đang rất vất vả cung cấp email cho chỉ 2.5 triệu khách hàng của MSN” … “Họ gọi chúng tôi đến gặp Bill [Gates] vào 13/10/1997 và chỉ chúng tôi xem cơ ngơi của Microsoft, trụ sở chính và mọi thứ. … Chúng tôi được dẫn vào một phòng với một cái bàn to khiếp, và ở đó có đến 15 nhà thương thuyết ngồi phía bên kia cái bàn, trong đó có dân phát triển doanh nghiệp, luật sư, và kế toán.  Họ phát biểu rằng họ thích chúng tôi thế này, thế kia, và vì thế họ muốn mua lại chúng tôi với giá 160 triệu đô.” … “Anh ta [CFO của Microsoft] muốn tôi mở miệng nhưng tôi đã được dặn trước là nếu như tôi mở miệng thì không có cách gì tôi có thể đàm phán với quá nhiều người như thế”.

Khi Livingston nhắc đến chuyện Bhatia đến Mỹ chỉ với 250 đô trong túi và tại sao anh lại không thấy hấp dẫn với lời đề nghị bán với giá cỡ 300 triệu, Bhatia cho rằng anh có nhất nhiều người dùng, và điều đó không dễ gì có thể đánh đổ được, kể cả khi Microsoft có hàng ngàn kỹ sư. Cuối năm 1997, Micosoft mua Hotmail với giá 400 triệu.

“Có thể là có ai đó có nhu cầu gì đó, và trong trường hợp của chúng tôi, chúng tôi có nhu cầu [sử dụng email]. Điều đó nảy sinh ra ý tưởng. Đôi khi ý tưởng nảy ra trong sự cần thiết nào đó: anh giải quyết vấn đề của anh, hi vọng là anh cũng giải quyết vấn đề đó cho rất nhiều người khác”.

(source: vietlabs)

Founders at Work: James Currier, Tickle

Năm 1999, Currier sáng lập ra trang Web tickle.com cho phép mọi người đánh giá cá tính và chính bản thân mình thông qua các bài test [mà phần lớn] có căn cứ khoa học nhằm tìm hiểu về hành vi con người. Tickle được Monster mua lại năm 2004 với khoảng 100 triệu đô la.

“Một tối tại lớp học [MBA], người ta đưa chúng tôi vài mẩu giấy và một chiếc bút chì số 2, và chúng tôi điền vào bài test cá tính trong doanh nghiệp của Myers-Briggs… Mọi người trong lớp bắt đầu bàn tán về bài test suốt 2 tuần liền – vào bữa tối, tại sân bóng rổ, vv. Tôi quan sát và nghĩ, “Mình chưa bao giờ thấy mọi người nói nhiều về một bộ phim lâu thế này. Đây hẳn là một phương tiện [truyền thông] đầy sức mạnh. Tại sao thế?”

“Có phải chúng ta là chủ đề yêu thích của chính mình? Chúng ta rất quan tâm đến bản thân mình và những người chúng ta quen biết. Tôi nhận ra rằng không có công nghệ nào khác cho phép chúng ta có được phương tiện [truyền thông] về chính mình. Tất cả các công nghệ truyền thông khác chỉ cho phép ta tìm hiểu về những người mà mình không hề quen biết. Tom Cruise, Tom Brokaw – chúng ta biết hàng tỉ thứ về họ nhưng sẽ không hề quen biết họ.

Tôi tin rằng Internet sẽ cho ta trải nghiệm truyền thông về chính mình và người quen… Và tôi nghĩ những bài test này sẽ thực sự mạnh mẽ bởi chúng ta thích nói về mình, về những người ta biết, và điều này sẽ lan tỏa như virus …

… Tôi biết hầu hết các công ty truyền thông trực tuyến đều bị giết chết bởi chi phí [để có người dùng], và tôi nhận ra rằng để xây dựng một công ty thành công, anh phải có chi phí cực thấp, nếu không nói là không có, để thu nạp người dùng.”

“Tôi phải hình dung ra những gì mà sản phẩm sẽ thực hiện. Rồi tôi phải nói chuyện với mọi người về nó và hỏi ý kiến họ. Có một sự cân bằng giữa việc nghĩ rằng anh có ý tưởng tuyệt vời này và anh không muốn ai biết, với nhu cầu bàn luận về nó và lấy ý kiến rộng rãi để anh mắc ít lỗi nhất đến mức có thể.”

“Tôi tin rằng có rất ít người có khả năng nhìn thấu tương lai. Và sẽ rất khó khi anh nói về những thứ mà chưa có gì tồn tại về nó”

“.. nếu như anh cho rằng những gì họ thấy là sai, điều đó sẽ rất không hay và họ sẽ ghét.”

“.. anh không bao giờ có đủ cho những người quanh anh. Bởi vì xây dựng một công ty là một hành động tập hợp và tổ chức năng lượng con người. … họ sẽ muốn biết hiện anh đang đứng đâu, và muốn anh đưa họ đi một bước nữa trên con đường và họ sẽ cảm thấy tự tin hơn. Họ luôn tìm kiếm những điểm tự tin. Ví dụ như: “Anh sẽ gọi nó là gì? Đặt một cái tên và chúng ta sẽ nói vế nó” … “Anh có kế hoạch kinh doanh không?” … “Anh có nhân viên không?” … “Anh có tiền không?” … “Anh có văn phòng chưa?” … “Anh có visit card không?” … “Anh có trang Web không?” … “Có ai đến trang đó chưa?” … ”

“… Chúng tôi có các bài test về sự lo lắng, về dạy dỗ con cái, về các mối quan hệ, và giao tiếp. Và không có ai đến [trang web]. Tôi nhớ là các nhà quảng cáo có nói là nếu anh muốn người ta nhớ một quảng cáo, hãy đưa vào đó trẻ con và thú cưng. Thế là tôi nghĩ, “Mình sẽ làm một bài test giải trí. Hãy cứ làm bài test xem anh có giống chó nào”. Thế là chúng tôi làm một bài test với 15 câu hỏi, và nó chẳng có căn cứ khoa học gì cả. Chúng tôi đưa lên mạng, và trong vòng 8 ngày sau đó chúng tôi có đến một triệu người truy cập. [Thế là] cứ sau 10 phút, sever của chúng tôi lại bị down.”

“iVillage.com bắt đầu bắt chước chúng tôi và tôi đã rất lo lắng trong suốt 1 năm, nhưng rồi nó cũng qua đi. Có thể là vì rất khó để các kỹ sư, nhà tâm lý học, và nhà văn nói chuyện với nhau. Anh phải xây dựng một văn hóa và giao tiếp giữa một nhóm nhỏ để họ có thể làm được việc [với nhau].”

“[Điều làm tôi ngạc nhiên nhất khi khởi nghiệp là] nó làm tôi đau đớn khủng khiếp. Tôi thức dậy vào ngày 3/10/1999 vào khoảng 4h sáng với lồng ngực bị thiêu cháy trong nỗi sợ hãi và đau đớn vì không biết làm gì và lo lắng đã lấy đi tiền của bè bạn và những người khác. Tôi nhận ra rằng những gì tôi đang gắng làm không hoạt động, và tôi không biết làm thế nào để giải quyết… Tôi đã tìm gặp 43 nhà đầu tư mạo hiểm.”

“[Khởi nghiệp] thực sự rất đau đầu và nó sẽ lấy đi cuộc sống của anh. Nếu anh quan tâm đến nó và nếu anh có cơ hội thành công, anh sẽ không còn xuất hiện trước những thứ êm ái hơn như gia đình, bè bạn và hò hẹn. Và khi anh đứng trước họ, anh cũng thực sự không xuất hiện ở đó; anh đang nghĩ về nó [công ty] vì anh đang tạo ra nó, và nó lấy đi mọi sự say mê để thành công.”

“… Tại một cuộc tái ngộ của HBS [Havard Business School], chúng tôi có một cái bàn tròn gồm tất cả những người đã từng khởi nghiệp, và một trong những giáo sư hỏi: “Có điều gì mà HBS chưa từng dạy anh?” Và tôi nói “Sự đau đớn”. Tôi chỉ nhớ là có một buối học duy nhất nhắc tới điều tương tự: một giáo sư bước ra khỏi lớp và đầy nước mắt, sau khi kể về một câu chuyện của một người bạn người đã từng khởi nghiệp từ một công ty dây cáp, và nó phá hủy cuộc đời anh, gia đình anh, và đẩy anh đến một nơi mà cuộc đời anh chỉ còn là một sự lãng phí của thời gian.”

 (Source: vietlabs )

Single & Double Quotes

First of all:
Double Quote Marks (“) have to be around an entire SQL Statement

If there is Limiter (non-numeric), like ‘where Fieldname=Peter’, where the limiter is not numeric, then you must put single quotes around it:

“Select * from Tablename where (Firstname)=’Peter’

This is an example of an EXACT SQL Statement. We are asking to return all instances of the name ‘Peter’.

Here’s where it gets tricky with variables. In our form, we are requesting a name, but whoever fills out the form might want to search for someone with a different name. So, since it can be different things to different people, we assign that section of the SQL statement a variable.

Let’s say you have designated a variable called FirstNameVar. Above where Peter starts is where the variable would go, but Peter is an exact search and a variable is not, so your SQL ending double quote goes directly after the single quote. This is where the EXACT SQL statement ends. At this point, you have:

“Select * from Tablename where (Firstname)=’”

Notice, that directly after the single quote is a double quote, just as if it were the end, but as you know, it isn’t. Think of how a response.write statement is in ASP.Net when we have html that needs to be in the response.write statement:
Response.write “Here is the the name You wanted” & myVar

The exact HTML is separated from the ASP. Well, in SQL, the same thing is happening. You are separating the EXACT SQL statement from the Variables.

OK, what about the variable? Well, you add an ampersand and the variable name:

“Select * from Tablename where (Firstname)=’” & FirstNameVar

But, we’re not finished yet, because, if you remember, the EXACT name must be surrounded by single quotes and the entire SQL statement must start & end with double quotes. Therefore, we must add the single quote, but also remember that it is still part of the EXACT SQL Syntax. And – in SQL, when you separate the EXACT SQL from the variables, each section of the EXACT SQL is enclosed within its own double quotes. The SQL statement, though, within the ASP.Net brackets is a separated text statement. The EXACT SQL is surrounded by quotes, where the variables aren’t. Remember, we are inside the ASP.Net brackets with this SQL statement and everything within double quotes is not considered ASP.Net code. So, we end up with:

“Select * from Tablename where (Firstname)=’” & FirstNameVar & “‘”

If you wanted to change out the “=” for “like”, then you would have an exact SQL like:

“Select * from Tablename where (Firstname)=’Peter%’

where this would find all instances of Peter as well as Peterman, Peterovsky, etc.
OR:

“Select * from Tablename where (Firstname)=’%Peter%’

– which would return to you any name which had the letters Peter anywhere in it.

With Variables, that would give you something like this:

“Select * from Tablename where (Firstname)=’%” & FirstNameVar & “%’”

Notice And, of course, this is only the first part because we are dealing with Non-numeric/text type values only. There are no single quotes around numeric values in an SQL statement.
So, if you put the single quotes around data and the data type of the field is numeric, you will get an error – a datatype mismatch error. Naturally, you need to be knowledgeable about the data structure of your table so that, for the fields that have a numeric datatype, you can go back and remove the single quotes around that field in the SQL statement.
For instance, if your statement looks like this:

MySQL="Select  * from data where age >'" & strAge & "'"

You will get an error on the Age field if, in your data structure, you have defined the Age field with a numeric datatype. You would need to change your statment to this:

MySQL="Select  * from data where age >" & strAge

Notice that the single quote before and after strAge have been removed. This will not give you an error. Then, of course, this principle is even more exemplified when using an INSERT statement. It boils down to one fact :

When you use single quotes, you are telling the database “the data I’m requesting (or INSERTING) is text”.
When you do not surround the data in your SQL statements with single quotes, you are telling the database “the data I’m requesting (or INSERTING) is numeric”.

So, as you can see it really pays to know your data!

Now – one Caveat – - Let’s say, you are inserting/updating a field where there is an apostrophe or single quote in the text itself. Since data is surrounded with single quotes, this would then cause a problem. It would actually end the text for that field at the point of the single quote/apostrophe. Then, the rest of the entire SQL statement is thrown off. To deal with this we can double the single quotes in the variable before it’s inserted into the database. By doing this, the database knows that two single quotes/apostrophes in a row mean that we actually want that character in the data. I normally recommend doing the replacement before the SQL statement so that the SQL statement is as clean and readable as possible. Here’s the basic VB.Net syntax for replacement:

MyVar = MyVar.Replace(“‘”, “””)

Don’t forget, though, to reverse the process when displaying the data from the database.In this tutorial, we’ve shown how to use single quotes and double quotes, with variables in an SQL statement and how to deal with single quotes/apostrophes with insert/update SQL statements. At this point, the rest is up to you!

(http://www.aspnet101.com/aspnet101/tutorials.aspx?id=2)

Creating Custom Exceptions in .NET

http://blog.gurock.com/articles/creating-custom-exceptions-in-dotnet/

Introduction
Minimal Exceptions Types
Serialization Basics
Customizing Serialization
Closing Words

Introduction

Although the .NET framework contains all kinds of exception types which are sufficient in most cases, it can make sense to define custom exceptions in your own applications. They can greatly simplify and improve the error handling and thus increase the overall code quality. Whatever your reasons are for using custom exceptions, this article shows you how to create them and what to pay attention to when it comes to serialization, .NET guidelines and analysis tools.

System or Application?

Any custom exception you create needs to derive from the System.Exception class. You can either derive directly from it or use an intermediate exception like SystemException or ApplicationException as base class. According to the .NET framework documentation, SystemException is meant only for those exceptions defined by the common language runtime whereas ApplicationException is intended to be used by user code:

“ApplicationException is thrown by a user program, not by the common language runtime. If you are designing an application that needs to create its own exceptions, derive from the ApplicationException class. ApplicationException extends Exception, but does not add new functionality. This exception is provided as means to differentiate between exceptions defined by applications versus exceptions defined by the system.”

So, ApplicationException seems like a good choice as base class for custom exceptions at first. But there has been quite a lot of discussion about this topic and according to this posting by a Microsoft employee working on .NET, the usage of ApplicationException is no longer recommended. It seems that the current .NET framework and its documentation is already outdated when it comes to the ApplicationException class:

“We added ApplicationException thinking it would add value by grouping exceptions declared outside of the .NET Framework, but there is no scenario for catching ApplicationException and it only adds unnecessary depth to the hierarchy. […] You should not define new exception classes derived from ApplicationException; use Exception instead. In addition, you should not write code that catches ApplicationException.”

So, the ApplicationException exception class will eventually be deprecated. I therefore let the custom exceptions here in this article derive directly from the Exception class.

Minimal Exceptions Types

The absolute minimum a new custom exception class needs to have is a name. Let’s say you are designing the login mechanism for a database application and as part of this job you need to create a custom exception which is thrown if a login attempt fails. A good name for such an exception would be LoginFailedException. An absolute minimum implementation in C# then looks like:

public class LoginFailedException: System.Exception
{
}

As you can see, all you need to do to create a basic custom exception is to derive from the Exception class. There’s only one problem with this definition. Since C# unfortunately doesn’t inherit constructors of base classes, this new type only has the standard constructor with no parameters and is therefore relatively useless. So, we need to add at least one constructor which does something useful:

public class LoginFailedException: System.Exception
{
   // The default constructor needs to be defined
   // explicitly now since it would be gone otherwise.

   public LoginFailedException()
   {
   }

   public LoginFailedException(string message): base(message)
   {
   }
}

By now we can use our custom exception like most other exceptions. We can throw an instance of LoginFailedException and pass a message which describes the occurred error. But .NET exceptions can do more. You can normally pass a so called inner exception to one of the constructors which indicates that the created exception is a direct result of a previous one. This inner exception can then be retrieved via the InnerException property. This way you can build entire exceptions chains. Since this can be quite useful sometimes, we extend our existing implementation with this additional constructor:

public class LoginFailedException: System.Exception
{
   // …

   public LoginFailedException(string message,
      Exception innerException): base(message, innerException)
   {
   }
}

Looks good so far. We now have a working custom exception which is capable of handling error messages and inner exceptions. Great!

Serialization Basics

Let’s now have a look at what FxCop says to our exception type. In case you don’t know what FxCop is, it’s a nice analysis tool which checks .NET assemblies for conformance to the .NET framework design guidelines. FxCop doesn’t seem to like our exception yet:

  • Error for ImplementStandardExceptionConstructors:
    Add the following constructor:

    LoginFailedException(SerializationInfo, StreamingContext)

  • Error for MarkISerializableTypesWithSerializable:
    Add [Serializable] as this type implements ISerializable

Doesn’t look that great anymore, does it? However, the good news is that this can be fixed quite easily. Both errors deal with the serialization mechanism of .NET in some way. In case you don’t know what serialization is, it’s basically a way to convert an object into a form which can easily be transported or persisted. The counter part to serialization is the deserialization which is responsible for restoring the original object.

Let’s begin with the second error. Any class that is intended to be serializable needs to be marked with the Serializable attribute and since our base class Exception implements the ISerializable interface which is used to customize the serialization process, FxCop wonders why we didn’t add it. So, in order to comply with the serialization guidelines, we simply need to add the Serializable attribute and the second error is already fixed:

[Serializable]
public class LoginFailedException: System.Exception
{
   // …
}

Correcting the first error is a bit more tedious. FxCop complains that we forgot to add an additional standard exception constructor. This constructor is used to customize the serialization process of objects. And since the base Exception class defines such a constructor and C# still lacks the support of constructor inheritance, we are better off adding such a beast:

[Serializable]
public class LoginFailedException: System.Exception
{
   // …

   protected LoginFailedException(SerializationInfo info,
      StreamingContext context): base(info, context)
   {
   }
}

Looks good. FxCop keeps quiet now and we finally have a fully functional exception type which can be used like any predefined exception. It can handle simple error messages and inner exceptions and can even be serialized and deserialized correctly.

Customizing Serialization

Let’s pretend we want to extend our exception by being able to store no only the error message why the login attempt failed, but also which username caused the error. This is pretty straightforward. We just add a new field and a new property to our existing class:

[Serializable]
public class LoginFailedException: System.Exception
{
   private string fUserName;

   // …

   public string UserName
   {
      get { return this.fUserName; }
      set { this.fUserName = value; }
   }
}

We are now able to set and get the name of the user specified during the login sequence. So far so good, but what about the serialization now? Does it still work as expected, that is, will the username be preserved when being serialized and deserialized? Unfortunately, the answer is ‘no’. You need to take care of it yourself.

Before we extend our exception to do exactly this, I tell you how the customization of the serialization and deserialization works in general. At first, you need to implement the ISerializable interface. This interface contains a single method, named GetObjectData, which is responsible for storing object fields during the serialization process. To do this, you just need to populate a passed SerializationInfo object.

The deserialization process works exactly the other way round. When an object is being deserialized, the previously filled SerializationInfo object is passed to the constructor of your class in which you are responsible for restoring the original object fields. Translated to our example exception, this looks like:

[Serializable]
public class LoginFailedException: System.Exception
{
   private string fUserName;

   // …

   protected LoginFailedException(SerializationInfo info,
      StreamingContext context): base(info, context)
   {
      if (info != null)
      {
         this.fUserName = info.GetString(”fUserName”);
      }
   }

   public override void GetObjectData(SerializationInfo info,
      StreamingContext context)
   {
      base.GetObjectData(info, context);

      if (info != null)
      {
         info.AddValue(”fUserName”, this.fUserName);
      }
   }
}

Let’s begin with the serialization. Since our base Exception class already implements the ISerializable interface we can omit it in the list of implemented interfaces and base classes and only need to override and fill the GetObjectData method. At first, we call the GetObjectData method of the base class. This is needed to save the fields common to all exceptions, like the error message, stacktrace information or the inner exception. Then we simply store our username by adding it to the passed SerializationInfo object.

The deserialization works similarly. We just restore our username field in the constructor with the aid of the previously filled SerializationInfo object. To verify that our custom exception works like expected and to demonstrate how an entire serialization and deserialization process looks like, I wrote the following unit test:

using System.Runtime.Serialization.Formatters.Binary;

// …

[Test]
public void TestUserName()
{
   LoginFailedException e = new LoginFailedException();
   e.UserName = “dotnet user”;

   using (Stream s = new MemoryStream())
   {
      BinaryFormatter formatter = new BinaryFormatter();
      formatter.Serialize(s, e);
      s.Position = 0; // Reset stream position
      e = (LoginFailedException) formatter.Deserialize(s);
   }

   Assert.AreEqual(e.UserName, “dotnet user”);
}

// …

During the serialization and deserialization process, the username field is now preserved correctly and thus the Assert class remains silent and the test passes. That this is not the case if we haven’t customized the serialization process can be confirmed quite easily. Simply comment out the GetObjectData method and the call to GetString in the constructor, rerun the test and you’ll see it failing since the UserName property will now return null instead of the correct username.

Closing Words

Aside from the ApplicationException versus Exception discussion, this article has been written with the .NET 1.1 version in mind. However, I don’t expect upcoming versions of the .NET framework to differ (greatly) from the techniques described here in this article, so that the information given here should still be of value in the future. As usual, if you have any comments or questions feel free to contact me at tg@gurock.com. Oh, and by the way, you can download the source of the LoginFailedException class and its test here.