title: OpenFileDialog filename as UTF8
body: <p>C# question here.. </p>
  
  <p>I have a UTF-8 string that is being interpreted by a non-Unicode program in C++.. This text which is displayed improperly, but as far as I can tell, is intact, is then applied as an output filename..</p>
  
  <p>Anyway, in a C# project, I am trying to open this file with an <em>System.Windows.Forms.OpenFileDialog</em> object.  The filenames I am getting from this object's <em>.FileNames[]</em> is in Unicode (UCS-2).  This string, however, has been misinterpreted.. For example, if the original string was <strong>0xe3 0x81 0x82</strong>, a FileName[].ToCharArray() reveals that it is now <strong>0x00e3 0x0081 0x201a</strong> .... .. It might seem like the OpenFileDialog object only padded it, but it is not.. In the third character that the OpenFileDialog produced, it is different and I cannot figure out what happened to this byte..</p>
  
  <p>My question is: Is there any way to treat the filenames highlighted in the OpenFileDialog box as UTF-8?</p>
  
  <p>I don't think it's relevant, but if you need to know, the string is in Japanese..</p>
  
  <p>Thanks,</p>
  
  <p>kreb</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>First of all, thanks to everyone who's offered their suggestions here, they're very much appreciated.</p>
  
  <p>Now, to answer the suggestions to modify the C++ application to handle the strings properly,  it doesn't seem to be feasible. It isn't just one application that is doing this to the strings.. There are actually a great number of these applications in my company that I have to work with, and it would take huge amount of manpower and time that simply isn't available. However, sean e's idea would probably be the best choice if I were to take this route..</p>
  
  <p>@Remy Lebeau: I think hit the nail right on the head, I will try your proposed solution and report back.. :) I guess the caveat with your solution is that the <em>Default</em> encoding has to be the same on the C# application environment as the C++ application environment that created the file, which certainly makes sense as it would have to use the same code page..</p>
  
  <p>@Jeff Johnson: I'm not pasting the filenames from the C++ app to the C# app.. I am calling OpenFileDialog.ShowDialog() and getting the OpenFileDialog.FileNames on DialogResult.OK.. I did try to use Encoding.UTF8.GetBytes(), but like Remy Lebeau pointed out, it won't work because the original UTF8 bytes are lost..</p>
  
  <p>@everyone else: Thanks for the ideas.. :)</p>
  
  <p>kreb</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>@Remy Lebeau: Your idea worked perfectly! As long as the environment of the C++ app is the same as the environment of the C# app is the same (same locale for non-Unicode programs) I am able to retrieve the correct text.. :) </p>
  
  <p>Now I have more problems.. Haha.. Is there any way to determine the encoding of a string? The code now works for UTF8 strings that were mistakenly interpreted as ANSI strings, but screws up UCS-2 strings. I need to be able to determine the encoding and process each accordingly. GetEncoding() doesn't seem to be useful.. =/ And neither is StreamReader's CurrentEncoding property (always says UTF-8)..</p>
  
  <p>P.S. Should I open this new question in a new post?</p>