company location

Get In Touch

Why not join us on Facebook? We only post about useful things like new releases, and unlike some others we promise we won't spam you with meassages!

 MLtek Software on Facebook       


 

 

Free .Net Symbolic Link Class

Home | About Us | Products | Support | Contact Us | Library

Our flagship product, ArchiverFS (details of which can be found here)  is a completely unique way to tackle old files on Windows based file servers. It has many brilliant features, and one of it's key options is the ability to generate completely seamless links to files that have been moved to a totally different volume on a completely separate server. We use Windows built in ability to work with Symbolic Links to generate the links, which are not the easiest thing to work with!

There is lots of PInvoke involved and it all gets rather complicated! We made extensive use of numerous online resources like PInvoke.netwhen working on this and benefitted greatly from numerous questions other people had posted on various forums like the ones at MSDN. Basically we wanted to give something back, so we decided to make one of our in-house libraries available to the general public as a way to say thank you.

So, if you want to work with Symbolic Links on Windows but are struggling to work it out please feel free to download and use the library below.

Download the MLtekSymLinkClass.

The assembly is built on .net 4.0 and can be added as a reference to any Visual Studio project. The namespace is 'MLtekSymLinkClass' and the main class is the 'UtilityClass'.

You will need to instantiate an instance of the class before you can use it...

VB.Net = Dim SymLinkObj As MLtekSymLinkClass.UtilityClass = New MLtekSymLinkClass.UtilityClass

C#.Net = MLtekSymLinkClass.UtilityClass SymLinkObj = new MLtekSymLinkClass.UtilityClass();

The Utility class provides three methods....

1) UtilityClass.CreateSymLink(File,Target) As Boolean

Used to create a new Symbolic Link. The File and Target parameters can be local drives, mapped network drives or even UNC paths. Supports full UNICODE for file paths.

The 'File' parameter (String) is the full file name including path of the Symbolic Link you want to create. The 'Target' parameter (String) is the full file name including path of the file you want the Symbolic Link to target.

Returns a Boolean value indicating if the operation was success.

2) UtilityClass.GetSymlinkTarget(Path)

Gets the full path of the target of the specified Symbolic Link.

The 'Path' parameter (String) if the full name including path of the symbolic link you want to get the target of. The path is returned as a string.

If an error is encountered an error code will be returned instead of the path.

-2 = Generic error reading from file
-1 = Generic error calling PInvoke to get file handle
1 -> 1000 = Win32 specific platform error code returned when opening handle to selected file.
1001 -> 2000 = Subtract 1000 to get Win32 specific platform error code returned when trying to read the target of the selected file.

3) UtilityClass.CopyDates(SourceFile, DestFile) as Integer

This function provides the ability to copy the 'last write time', 'last accessed time' and 'created time' timestamps from any file to a Symbolic Link.

The 'SourceFile' parameter (String) is the file you want to copy the timestamps from, and the 'DestFile' parameter (string) is the Symbolic Link you want to copy the timestamps too.

The return value is an Integer...

0 = Ok
-2 = Generic error reading times from source file
-1 = Generic error calling PInvoke to get file handle
1 -> 1000 = Win32 specific platform Error code returned when opening handle to destination file
1001 -> 2000 = Subtract 1000 to get Win32 specific platform Error code returned when setting Date\Time on destination file

This Assembly is provided as is without any warrenty or guarntee what so ever. It is free for non-commercial use and all rights and ownership remain with MLtek at all times.

By downloading, accessing and\or using it you accept these conditions.

Enjoy :-)