PDA

Click to See Complete Forum and Search --> : OS - Capabilities - NTFS - File Streams - VB Implementation


KayJay
Jun 11th, 2003, 07:32 AM
One of the neat features of the NT File System is its capacity to work with file streams. File Streams are extensions of the File Contents. Right Click on a file in an NTFS Hard Disk and you will find a "Summary" tab which has fields such as "Title', "Author", "Comments". To read and write from these fields (streams), I have not been able to do so, yet. If any of you can or have an idea, please post in the following thread.

http://www.vbforums.com/showthread.php?s=&threadid=247931

However, the code below will create named streams and add/retrieve data to those streams. Usages could range from maintaining a "Folder" in a Single File, Storing Security Settings, "Piggy Back" hidden applications, etc. Note that incorrect file sizes (a zero byte file as displayed in Windows Explorer can have Y MB of data in various streams) is a drawback using such a technique.

'Stream are accessed as normal files
'but using FILENAME:STREAMNAME as the file's name
Option Explicit
Private Sub Command1_Click()
Dim strFileName As String
Dim intFN As Integer
Dim strTemp As String

strFileName = "D:\text.txt"

intFN = FreeFile
Open "D:\Winnt\notepad.exe" For Binary As #intFN
strTemp = Space(LOF(1))
Get #1, , strTemp
Close #intFN

WriteStream strFileName, "Author", "Kaushik Janardhanan"
WriteStream strFileName, "Category", "VB Code Snippets"
WriteStream strFileName, "Comments", "This stuff is really usefull!"
WriteStream strFileName, "Title", "NTFS File Streams"
WriteStream strFileName, "Reference", "VBFORUMS-1234"
WriteStream strFileName, "Executable", strTemp

MsgBox "Author" & vbCrLf & ReadStream(strFileName, "Author") & _
vbCrLf & vbCrLf & _
"Category" & vbCrLf & ReadStream(strFileName, "Category") & _
vbCrLf & vbCrLf & _
"Comments" & vbCrLf & ReadStream(strFileName, "Comments") & _
vbCrLf & vbCrLf & _
"Title" & vbCrLf & ReadStream(strFileName, "Title") & _
vbCrLf & vbCrLf & _
"Reference" & vbCrLf & ReadStream(strFileName, "Reference")

Shell strFileName & ":Executable", vbMaximizedFocus
Unload Me

End Sub

Private Sub WriteStream(strFile As String, strStream As String, strContents As String)
Dim intFN As Integer

intFN = FreeFile

Open strFile & ":" & strStream For Binary As #intFN
Put #intFN, , strContents
Close #intFN

End Sub

Private Function ReadStream(strFile As String, strStream As String) As String
Dim intFN As Integer
Dim strTemp As String

intFN = FreeFile

Open strFile & ":" & strStream For Binary As #intFN
strTemp = Space(LOF(intFN))
Get #intFN, , strTemp
Close #intFN

ReadStream = strTemp

End Function

This author has just recently encountered the above. Please do respond with details of any inaccuracies, inconsistencies and possible suggestions for improvements, usages, etc.

For a brief introduction to NTFS Filestreams, please visit http://www.msdnaa.net/Resources/Dis...sID=569#sample1

Thank you

Regards

Kaushik Janardhanan