Click here to Skip to main content
12,831,378 members (33,822 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads


129 bookmarked
Posted 31 Jul 2002

Accessing alternative data-streams of files on an NTFS volume

, 15 Aug 2016 CPOL
A pair of classes to encapsulate access to NTFS alternative data streams.
using System;
using System.Drawing;

/// <summary>
/// A console app to test the NTFS class.
/// </summary>
namespace NTFS.Test
	class TestNTFS
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		static void Main(string[] args)

		static void TestStream() 
			const string IMAGE_FILE = @"test.jpg";
			const string THUMB_STREAM = "thumb";

			//List all of the alternative streams for the file:
			NTFS.FileStreams FS = new NTFS.FileStreams(IMAGE_FILE);
			foreach(NTFS.StreamInfo s in FS) Console.WriteLine("\t" + s.Name);
			//Using an alternative stream to store a thumbnail image:
			System.Drawing.Image thm;
			System.IO.FileStream FileStream;
			int i = FS.IndexOf(THUMB_STREAM);
			if (i==-1) 
				//Thumbnail stream not found - create and store the thumbnail:
				Console.WriteLine("Creating thumbnail:");
				System.Drawing.Image img = System.Drawing.Image.FromFile(IMAGE_FILE);
				int Width = 100; int Height = 100;
				//Maintain aspect ratio:
				int lW = (int)(img.Width * Height / img.Height);
				int lH = (int)(img.Height * Width / img.Width);
				if (lW>Width) Height = lH;
				else if (lH>Height) Width = lW;
				thm = img.GetThumbnailImage(Width, Height, null, IntPtr.Zero);
				//Save the thumbnail to the stream
				FileStream = FS[THUMB_STREAM].Open(System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
				thm.Save(FileStream, System.Drawing.Imaging.ImageFormat.Jpeg);
				Console.WriteLine("Created thumbnail: Size {0}x{1}", thm.Width, thm.Height);
				//Thumbnail stream exists - read the thumbnail back
				Console.WriteLine("Thumbnail already exists!");
				FileStream = FS[THUMB_STREAM].Open(System.IO.FileMode.Open, System.IO.FileAccess.Read);
				thm = System.Drawing.Image.FromStream(FileStream);
				Console.WriteLine("Read thumbnail: Size {0}x{1}", thm.Width, thm.Height);
				//Remove the thumbnail stream, for demo purposes only!

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Richard Deeming
Software Developer Nevalee Business Solutions
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170326.1 | Last Updated 15 Aug 2016
Article Copyright 2002 by Richard Deeming
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid