I am having problems with encoding in ID3 tags. I query a webservice which returns back some XML including a node such as the one below:
<name>Blue Öyster Cult</name>
I am then using this information to update my ID3 tags. The problem is that the tag is updated as:
Blue Öyster Cult
I know this is an encoding issue, but I’m struggling to work out how to get it to work. My understanding is that ID3 tags need to be encoded as ISO-8859-1.
I wrote this code, but it makes no difference:
Encoding newEncoding = Encoding.GetEncoding("ISO-8859-1");
Encoding utf8 = Encoding.UTF8;
byte[] utfBytes = Encoding.UTF8.GetBytes(newArtistName);
byte[] asciBytes = Encoding.Convert(utf8, newEncoding, utfBytes);
string encodedArtistName = newEncoding.GetString(asciBytes);
Is this in the right direction or not?
Any advice much appreciated.
The issue that I was having was actually prior to saving to the ID3 tags. The XML I was receiving was set to UTF-8, but the WebClient requesting the page was not. Adding the second line shown here resolved the problem.
When the value is extracting from this XML, it has the correct encoding to be saved to the files ID3 tag.