Click here to Skip to main content
11,712,454 members (74,555 online)
Click here to Skip to main content

HardLinks - Manage your library of common classes

, 5 Mar 2004 CPOL 52.5K 1.3K 29
Rate this:
Please Sign up or sign in to vote.
A tool for managing NTFS hard links

Sample Image - HardLinks.jpg


I have some classes that I reuse in many projects. I wanted a way to share these files between projects, while always updating a "master" copy that is the latest version. The NTFS support for hard links seems to be an answer. I can now keep all the master files in one directory, and link to the files I want to use from individual projects.


NTFS hard links allow a file to appear in more than one directory with more than one name. Unix users will be familiar with this concept.

Because this can get very confusing very quickly, I have assumed some rules.


  • Real files are stored in just a couple or so directories. I use "C:\dev\Common" and "C:\dev\Common\Icons".
  • Link files are stored in a separate directory to the rest of the project files. I use "<project>\Common" and "<project>\Icons".
  • Link file names are the same as the real file names.

Using the code

  • First, create your real file directory using Explorer.
  • Add your common files to this directory using Explorer. I have included the file Cursors.cs from my WaitCursor article to get you started.
  • Create your link directory using Visual Studio. In Solution Explorer, right-click your project and select "Add/New Folder". Name it "Common".
  • Fire up the HardLinks exe. Click the Add Directory button ( Open File icon ).
  • Set your real and link directories in the dialog and press ok.

You should now have your real and link file directories selected in the list boxes on the left, and the Cursors.cs file in the checked list box on the right.

  • Check Cursors.cs to create a link file. If you look at your link file directory with Explorer, you will see the Cursors.cs file. We know that this is really a link, not a separate file.
  • Go back to Visual Studio and right-click your Common folder in your project. Select "Add/Add Existing Item" and pick the Cursors.cs file.

You now have the link to the real file in your project.

This may seem a bit complicated, but it gets easier as you add more common files.

Points of Interest

The checked list box on the right lists all the files in the selected real directory. The check state indicates the files in the link directory.

You can see the Legend from the context menu, but here are the states and their meanings :

  • Unchecked : No file exists
  • Indeterminate : File exists, but is a real file not a link
  • Checked : Link exists.

Be careful not to delete real files!

This applies to icon files especially, as Visual Studio overwrites them when you edit them, instead of just updating their contents. If you have to edit an icon file, then manually select the file in your real file directory, or you will just make a copy in your link file directory which is what we're trying to avoid.

The code is not very interesting. It is mostly GUI stuff, but I have included it in case you want to modify it.


I have included this app in the zip files. It is an optional install with Visual Studio - under C++ Tools I seem to remember.

Point to the exe in the Options, or just put the exe in the application directory and you can immediately compare the currently selected real and link file directories.


I used the Magic Docking Library by Phil Wright. It made life very easy, so I give it a 5.


  • Version 1 : 2004 March 6 : First version.


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


About the Author

Nicholas Butler
United Kingdom United Kingdom

I built my first computer, a Sinclair ZX80, on my 11th birthday in 1980.
In 1992, I completed my Computer Science degree and built my first PC.
I discovered C# and .NET 1.0 Beta 1 in late 2000 and loved them immediately.
I have been writing concurrent software professionally, using multi-processor machines, since 1995.

In real life, I have spent 3 years travelling abroad,
I have held a UK Private Pilots Licence for 20 years,
and I am a PADI Divemaster.

I now live near idyllic Bournemouth in England.

If you would like help with multithreading, please contact me via my website:

I can work 'virtually' anywhere!

You may also be interested in...

Comments and Discussions

Generalmuch more easier way... Pin
Vlad Tepes6-Mar-04 7:40
memberVlad Tepes6-Mar-04 7:40 
... is to use VS.NET
When you choose "Add existing item" do not click "Open" button (in a FileDialog) but instead click an arrow just beside the "Open" button. Select "Link" option and you will have selected file added to VS solution as a "linked" file (with small arrow indicating a link on the file icon).
When you then modify that shared file your changes always affect a single "master" file, as it isn't copied into project directory but "linked" (stays in the same directory all the time no matter how many projects use that file)

I think it is a really easy method to use common class library Wink | ;)
GeneralRe: much more easier way... Pin
Nicholas Butler6-Mar-04 19:08
memberNicholas Butler6-Mar-04 19:08 
GeneralRe: much more easier way... Pin
rromerot8-Mar-04 1:48
memberrromerot8-Mar-04 1:48 
GeneralFor reference Pin
Norm Almond6-Mar-04 6:14
memberNorm Almond6-Mar-04 6:14 
GeneralRe: For reference Pin
Nicholas Butler6-Mar-04 19:00
memberNicholas Butler6-Mar-04 19:00 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150819.1 | Last Updated 6 Mar 2004
Article Copyright 2004 by Nicholas Butler
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid