Friday, November 21, 2008

ADSdotNET – Access NTFS Alternate Data Streams from your managed languages without P/Invoke

CodeProject - ADSdotNET: A DLL for using alternate data streams from .net languages


ADSdotNET is a library which makes it possible for .NET-based programming languages like C# or Visual Basic .NET to access alternate data streams (ADS). Without this DLL it would be neccessary to use P/Invoke or C++/CLI to work with ADS and to benefit from .net-based languages at the same time.

ADSdotNET was developed in C++/CLI by the way. The zip file contains a Visual Studio 2005 project. The other zip file ( contains the compiled DLL only.


When I tried to access ADS from my C# code I found out that the .NET framework currently does not support file streams. So I decided to write a class which I could use for my C# project. I decided to use C++/CLI for writing ADSdotNET because in my opinion using this language for accessing the Windows API is more "natural" than using P/Invoke.

Using the code

After including the DLL as reference in your Visual Studio project (you can do that in the Solution Explorer) you can see a new entry inside the folder References named ADSdotNET.

From now on you can use a new namespace called AdsDotNet. It contains the class AdsHandler. First of all you have to create an object of this class. Every object of type AdsHandler points to one file or directory. The methods of these objects can be used for adding/deleting/modifying the alternate data streams of the corresponding file or directory (will be called “root object” in the future). To root objects alternate data streams can be attached.

Now I will describe the methods of the class AdsHandler. Examples will help to understand the usage (I hope).


mickbitsoftwareAdsManager [GD: AdsManager is a C# application written using the ADSdotNET library...]

“AdsManager is a tool to find, add, or remove alternate data streams on NTFS-formatted drives.

Many applications cannot access ADS because they think colons are invalid characters in filenames. For that reason applications based on .NET Framework are not capable of using alternate data streams as well.

The DLL shipped with AdsManager makes it possible for .NET applications to access ADS anyway. Internally it uses native Windows API functions (which can deal with ADS) and provides an interface for .NET developers.


NTFS Alternate Data Streams is just one of those things I know I’m going to need to do more with one day…


Related Past Post XRef:
Accessing NTFS Alternate Data Streams with C#
CopyFileEX ALL API Example
"Practical Guide to Alternative Data Streams in NTFS"

No comments: