Brent
Brent

Reputation: 4896

.net get/set file description property

I am writing an application in .net 4 (MVC 4), and the user has the ability to upload files.

I would like to store a brief description of the file, and the easiest place to put this info is in some kind of 'description' attribute associated with the file or filesystem.

I do have a database the application is using, and so can resort to storing this kind of information in the database if that is the best way to do things.

A bit of searching revealed the FileVersionInfo.FileDescription property within the System.Diagnostics namespace. However, this only has a get accessor.

Does anyone know a useful property with get/set accessors to store small strings? The files will be only pdf, open-office or microsoft office formats.

Thanks

Upvotes: 0

Views: 526

Answers (2)

tumtumtum
tumtumtum

Reputation: 1162

Jim is right that you're probably best off storing this kind of meta-data in a database. If you're dead set on using extended attributes, this wiki for my OSS Plaform.VirtualFileSystem library makes is very easy to read/write attributes (stored as NTFS alternate data streams).

https://github.com/platformdotnet/Platform.VirtualFileSystem/wiki/Advanced-Attribute-Access

For example:

var file = FileSystemManager.Default.ResolveFile("temp://test.txt");

file.Attributes["extended:customattribute"] = "Hello";

Upvotes: 0

Jim Mischel
Jim Mischel

Reputation: 134125

There really isn't a general way to attach attributes to arbitrary files. There are NTFS alternate data streams, but there are many caveats to their use.

The FileVersionInfo stuff is used for executables (.exe, .dll), but it's part of the file format. It's not something that you can just attach to an arbitrary file.

Some file formats include the facility for you to add information. JPEG images, for example, let you add attributes, and MP3 files let you add ID3 information. I don't know if PDF and Open Office formats have such a facility. Microsoft Office documents have some such facility, in that you can add the author's name and other metadata that isn't actually part of the document (i.e. is not printed when you print a Word document, for example). That information, though, is subject to change by anybody who opens the file in Word (or other Office application).

In any case, if you want to add metadata to a file, you'll have to customize that information for each file format that you want to add it to. Adding metadata to a PDF, for example (if that's possible), would be different from adding the same metadata to an Open Office or Microsoft Office document.

You're probably better off using a separate database to keep track of that information.

Upvotes: 2

Related Questions