Search code examples
c#.netntfsalternate-data-stream

How to read and modify NTFS Alternate Data Streams using .NET


How can I read and modify "NTFS Alternate Data Streams" using .NET?


Solution

  • Not in .NET:

    http://support.microsoft.com/kb/105763

    #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);
       }