Trying to write a keyword windows metadata element using C #

We have a couple of people right now browsing a directory of thousands of jpg and manually setting the tag metadata item to them in Windows Explorer. I want to hack something to just read the table they get the tags from and apply them to the files.

In the research I have done, it appears that the "Tags" metadata in Windows is actually the "Keywords" xmp metadata. I was able to read this metadata using the following code:

FileStream fs = new FileStream(@"C:\test.jpg", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
        BitmapSource img = BitmapFrame.Create(fs);
        BitmapMetadata md = (BitmapMetadata)img.Metadata;
        StringBuilder tags = new StringBuilder();
        foreach (String s in md.Keywords)
        {
            tags.Append(s);
            tags.Append(";");
        }
        String fin = tags.ToString();

      

The problem is that the Keywords property is a read-only collection. I found a few "potential" ones when writing this metadata, but none of them seem to work. It especially sucks because if I open the file in notepad ++ I can see exactly where the metadata is stored, but the amount of xml tags around it is pretty messy that trying to just slow things down there won't work. Does anyone have any information on how to write jpg keywords metadata on Windows using C #?

Just to show that I've actually tried, here are a bunch of links I've tried to use:

+3


source to share


1 answer


After a lot more searches (with keywords that don't make a lot of sense), I finally found this other question that tells how to do it with the Windows API Code Pack: Is it possible to set / change extended file properties using the API Code Pack Windows?

For a pretty penny, open your package manager console in VS and type Install-Package WindowsAPICodePack



MS pulled this package themselves from the MSDN archive, so NuGet is the only way to get it. The numbers they'll make are 50 times harder than necessary, especially since the MSDN article on their property system brags about how this is the future of Windows file management.

+1


source







All Articles