3

I'm trying to port a .NET Framework application to .NET Core. That application reads the extended properties of a file, like one can see when right clicking on a file in the File Explorer:

enter image description here

In my 4.7.2 Framework application, the code looked like this:

using Microsoft.WindowsAPICodePack.Shell;
      
var shellFile = ShellFile.FromFilePath(file.FullName);
var title = shellFile.Properties.System.Title.Value;
var albumTitle = shellFile.Properties.System.Music.AlbumTitle.Value;

My project referenced the Shell code like this:

enter image description here

What do I need to do in my .NET Core application to get access to the code of Microsoft.WindowsAPICodePack.Shell ? Or does .NET Core offer another way how to read those file properties ?

Before you mark this question as dupplicate

I know that a similar question was asked already: Obtaining file extended properties in .Net Core

However, this question was asked 3 years ago, when .NET Core was very young. The 2 answers do not explain how to read the extended properties of a file. It seems the people answering did not understand the difference between extended file properties and the file properties one can get from FileInfo. Maybe the question was not clear enough ? I also hope that .NET Core has improved enough that such legacy functionality can get used again.

Peter Huber
  • 3,052
  • 2
  • 30
  • 42

1 Answers1

4

I don't think these are file attributes. I guess, it is MP3 metadata stored in ID3 tags.

You are using .NET Framework NuGet package WindowsAPICodePack-Shell that can read such metadata.

Option #1

I couldn't find a .NET Core version of the original package. But I found an unofficial .NET Core fork of the library: Microsoft-WindowsAPICodePack-Shell (it's not authored by Microsoft).

Option #2

For .NET Core you can install the TagLibSharp NuGet package. And then you just read metadata like this:

var file = new FileInfo("track.mp3");
var tagLibFile = TagLib.File.Create(file.Name);
var title = tagLibFile.Tag.Title;
var album = tagLibFile.Tag.Album;
var albumArtist = tagLibFile.Tag.AlbumArtists;
var genres = tagLibFile.Tag.JoinedGenres;
var length = tagLibFile.Properties.Duration;
Vlad DX
  • 4,200
  • 19
  • 28
  • 1
    There are actually a number of Microsoft-WindowsAPICodePack-Shell on Nuget, one even from Microsoft. However, that last one might not run on Core ? I can't figure it out. The others say that MS gave up maintenance on WindowsAPICodePack code and that the other forks are also outdated. Which makes me worried about the reliability and future of all forks. What a mess. Thanks for the TagLibSharp idea, I might give it a try, although I would prefer to use MS only dlls. – Peter Huber Nov 08 '20 at 12:55
  • 1
    TagLibSharp works like a charm. Now I only hope that it will continue to do so in 30 years with .NET framework 2050. – Peter Huber Nov 09 '20 at 07:57
  • I had a look at `TagLibSharp`, but wasn't able to find how to get the file Tags. I could get other data, just not the `Tags`. – JonathanPeel Dec 26 '21 at 17:44
  • 1
    @JonathanPeel, have you tried the code snippet from the answer? It shows how to read tags through the `TagLib.File`.`Tag` property. – Vlad DX Dec 28 '21 at 22:06
  • @vlad-dx, these are not the tags I am looking for. When I open the properties, under the `Comments` field (visible on the image above) I have a field called `Tags`. It seems these are meta data based on the file type. My initial assumption was that this was a part of the file system (like on a Mac you can add tags and colour labels to a file). Because of this, what I decided to do is use this library, and add my tags as CSV to the `Comments` field. – JonathanPeel Dec 29 '21 at 06:57
  • 1
    @JonathanPeel, the original question didn't explicitly state. But it was about MP3 files. ID3 tags are MP3 files feature. Therefore, `TagLibSharp` only helps with them, not anything else. – Vlad DX Dec 31 '21 at 09:05
  • @vlad-dx, I did see that. And the answer was still useful to me, so I did give it an arrow up. Thank you – JonathanPeel Jan 01 '22 at 11:36