Attributes of a file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way to add Comments (right click on a file, in the summary tab
this information will be present) to a file in C#. I searched through
FileInfo class, but I could not find any properties or methods to add
comments.
 
Rohith,
Is there a way to add Comments (right click on a file, in the summary tab
this information will be present) to a file in C#.

Yes there is, but I'm afraid the .NET Framework doesn't support this
directly. And, unfortunately the process is somewhat more difficult than you
might think at first.

Before we start, you need to understand something about so-called NTFS
Alternative Data Streams (ADSs). These streams allow you to associate
"hidden" data with any file, and this is what Windows Explorer does when you
associate summary information with the file, i.e. go to file properties
dialog box and its Summary tab on Windows 2000/XP/2003. If all this sounds
very new to you, I suggest reading for example this Dino Esposito's
introduction:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/ntfs5.asp

Now, these alternate streams are somewhat a double-edged sword as they can
be used to store both useful and not-so-useful data. See for instance here:

http://www.relsoft.net/datastreams.html

Setting the potential security issue aside, you need to be able to read and
write a special stream to your file to be able to associate summary
information with it. To do it, you would need to use some Windows API
functions. I couldn't find C# examples with quick surfing, but here's a
Delphi one:

http://www.delphipages.com/news/detaildocs.cfm?ID=104

Here's also an interesting Windows Shell Extension from The Code Project:

http://www.codeproject.com/csharp/CsADSDetectorArticle.asp

And, yet another article that you might find useful:

http://msdn.microsoft.com/msdnmag/issues/0300/w2kui/

Hope this gets you started!

--
Regards,

Mr. Jani Järvinen
C# MVP
Helsinki, Finland
(e-mail address removed)
http://www.saunalahti.fi/janij/
 
Hi,

It's not supported in .net it's a feature of NTFS , you can have more than
one stream of data, usually the first (default) is the file itself, you can
use others to store info, I tried once to use a dll from MS:
http://support.microsoft.com/?id=224351 as I needed it exclusively for
office documents, try it and see if you can use it for other kind of files.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top