Getting specific file attributes

I have a simple WCF service that allows clients / consumers to upload images, audio or video files to it. After loading, the service should analyze the file and somehow extract the following attributes:

Image: width, height, date, used program

Audio: time of execution, artist, album, genre, bitrate, year of publication.

Video: runtime, width, height, frames / sec, video bitrate, audio bitrate.

Obviously, Windows can display these attributes easily and easily, but how to do it in C #?

+8
c # file-attributes file-properties
source share
2 answers

Adherence to this topic.

I checked that it gets all file attributes, including extended attributes.

In your project, go to "Add Link" -> COM -> "Microsoft Shell Controls and Automation"

Add this, and again kindly provide the mentioned stream, the C # method, to read the attributes of the files in the directory. (I am still investigating whether this function can be executed in a specific file. If not, you can always pass the specified file name and check only to get the attributes for that file.)

public static void Main(string[] args) { List<string> arrHeaders = new List<string>(); Shell32.Shell shell = new Shell32.Shell(); Shell32.Folder objFolder; objFolder = shell.NameSpace(@"C:\temp\testprop"); for( int i = 0; i < short.MaxValue; i++ ) { string header = objFolder.GetDetailsOf(null, i); if (String.IsNullOrEmpty(header)) break; arrHeaders.Add(header); } foreach(Shell32.FolderItem2 item in objFolder.Items()) { for (int i = 0; i < arrHeaders.Count; i++) { Console.WriteLine("{0}\t{1}: {2}", i, arrHeaders[i], objFolder.GetDetailsOf(item, i)); } } } 
+7
source share

The easiest way to access this information is to let Shell (Explorer) do it for you and just ask (through the Windows Property System ) for this. And the easiest way to do this from C # is probably to use the Windows API Code for .NET .

In particular, you will want to access the property store. To get started, look in the Samples folder in the PropertiesEditDemo project.

You can do this yourself by reading all the metadata for the file, but the problem is that your program should know all the metadata available for all available file types. I usually prefer to hang on Shell for this knowledge.

+2
source share

All Articles