1

I want to extract file/folder and other item type that contains some German special characters in their name from Livelink server. Livelink server has encoding UTF-8. Value is Test Dokument äöüß

      var bytes = new List<byte>(value.Length);
        foreach (var c in value)
            bytes.Add((byte)c);
        var retValue = Encoding.UTF8.GetString(bytes.ToArray());

the above code sample fixes s encoding problem in some character but ß is seen as ? character in Latin( ISO 8859-2) encoding. can anybody help me fix the problem.

Thanks in advance

Shyam sundar shah
  • 2,473
  • 1
  • 25
  • 40
  • 2
    It's *really* unclear what you're actually trying to do... and using this approach is pretty much always inappropriate. It's not clear what "encoding problem" you've actually got, nor what data you're actually getting from Livelink, or how you're trying to display it. I'd strongly encourage you *not* to use the code you've already got, but we can't help you get to better code without more context. – Jon Skeet Sep 01 '13 at 09:07

2 Answers2

0

You have to set UTF-8 encoding on the LL session:

LLSTATUS llSessionStatus = LL_SessionAllocEx( &llSession, server, port,  "",  login, password, NULL);
LLSTATUS status = LL_SetCodePage( llSession , LL_TRUE, LL_TRUE, (LLLONG) 65001 );

65001 - is the codepage for UTF-8

Michał Turczyn
  • 32,028
  • 14
  • 47
  • 69
MaxEMunich
  • 21
  • 3
-1

It doesn't make sense to store ISO-8859-1 in a C# string, since it stores Unicode characters.

What really makes sense is to convert the Unicode string into a byte[] representing the string in ISO-8859-1.

var test ="äöüßÄÖÜ";
var iso = Encoding.GetEncoding("ISO-8859-1");
var bytes = iso.GetBytes(test);
File.WriteAllBytes("Sample file ISO-8859-1.txt", bytes);

Try this and you'll see that the text file is correctly encoded.

You can even check with a hex editor or with the debugger that the ß is correctly encoded as 0xDF (see table on wikipedia)

Benoit Blanchon
  • 13,364
  • 4
  • 73
  • 81