Help and Support

How To Use NTFS Alternate Data Streams

Article ID:105763
Last Review:November 21, 2006
Revision:4.2
This article was previously published under Q105763
On This Page

SUMMARY

The documentation for the NTFS file system states that NTFS supports multiple streams of data; however, the documentation does not address the syntax for the streams themselves.

The Windows NT Resource Kit documents the stream syntax as follows:
filename:stream
Alternate data streams are strictly a feature of the NTFS file system and may not be supported in future file systems. However, NTFS will be supported in future versions of Windows NT.

Future file systems will support a model based on OLE 2.0 structured storage (IStream and IStorage). By using OLE 2.0, an application can support multiple streams on any file system and all supported operating systems (Windows, Macintosh, Windows NT, and Win32s), not just Windows NT.

Back to the top

MORE INFORMATION

The following sample code demonstrates NTFS streams:

Back to the top

Sample Code

   #include <windows.h>
   #include <stdio.h>

   void main( )
   {
      HANDLE hFile, hStream;
      DWORD dwRet;

      hFile = CreateFile( "testfile",
                       GENERIC_WRITE,
                    FILE_SHARE_WRITE,
                                NULL,
                         OPEN_ALWAYS,
                                   0,
                                NULL );
      if( hFile == INVALID_HANDLE_VALUE )
         printf( "Cannot open testfile\n" );
      else
          WriteFile( hFile, "This is testfile", 16, &dwRet, NULL );

      hStream = CreateFile( "testfile:stream",
                                GENERIC_WRITE,
                             FILE_SHARE_WRITE,
                                         NULL,
                                  OPEN_ALWAYS,
                                            0,
                                         NULL );
      if( hStream == INVALID_HANDLE_VALUE )
         printf( "Cannot open testfile:stream\n" );
      else
         WriteFile(hStream, "This is testfile:stream", 23, &dwRet, NULL);
   }
				
The file size obtained in a directory listing is 16, because you are looking only at "testfile", and therefore
type testfile
produces the following:
   This is testfile
				
However
type testfile:stream
produces the following:
   The filename syntax is incorrect
				
In order to view what is in testfile:stream, use:
more < testfile:stream
-or-
mep testfile:stream
where "mep" is the Microsoft Editor available in the Platform SDK.

Back to the top


APPLIES TO
Microsoft Win32 Application Programming Interface, when used with:
  Microsoft Windows NT Advanced Server 3.1
  Microsoft Windows NT 4.0
  Microsoft Windows NT 3.51 Service Pack 5
  Microsoft Windows NT 4.0
  Microsoft Windows 2000 Standard Edition
   the operating system: Microsoft Windows XP

Back to the top

Keywords: 
kbhowto kbapi kbkernbase kbfileio KB105763

Back to the top

Article Translations

 

Other Support Options

  • Contact Microsoft
    Phone Numbers, Support Options and Pricing, Online Help, and more.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.