title: Converting UTF-8 to UTF-16BE
body: <p>I'm wrestling with the following problem. 
  I am working with V.S.10 and using the .NET framework 2.0. Coding in C#.</p>
  
  <p>I'm making a simple editor which hands over its text to a <strong>webservice</strong>. I know that .NET uses UTF-16 (I believe the default is LE? And I want Big Endian). I want to make it able to work in any editor and therefore attatch a BOM. The problem is that going through httml it gets changed I believe to UTF-8? Or at least that is what it seems from the following error:</p>
  
  <pre><code>Client found response content type of 'text/html; 
  charset=UTF-8', but expected 'text/xml'. 
  The request failed with an empty response.
  </code></pre>
  
  <p>EDIT: the documentation warns that the encoding of all the properties are UTF-8 withOUT a BOM marker. editorTextString is one of the properties. BUT the file content to upload must be in UTF-16BE WITH a BOM. I've checked to see if .net automatically translates the encoding and it does not. Or at least the chinese letters become ?'s. So I need to re-encode or convert better said, the text to UTF-16BE WITH BOM instead of the UTF-8 without BOM that it is in now.</p>
  
  <p>I've looked through a ton of examples and can't see what I'm doing wrong here. Can someone offer advice or correct the code? (Yes I've also read Jon's really cool article about unicode :)) The theory is clear, the actual practice is lacking. </p>
  
  <pre><code>        // Convert to UTF-16 Big Endian
  
          Encoding leUnicode = Encoding.Unicode; 
          Encoding beUnicode = Encoding.BigEndianUnicode;
  
          byte[] editorTextBytesLE = leUnicode.GetBytes(editorTextString);
          Console.WriteLine("Little Endian - Encoded bytes:");
          foreach (Byte b in editorTextBytesLE)
          {
               Console.Write("[{0}]", b);
          }
          Console.WriteLine();
  
          byte[] editorTextBytesBE = Encoding.Convert(leUnicode, beUnicode, editorTextBytesLE);
          Console.WriteLine("BIG ENDIAN - Encoded bytes:");
          foreach (Byte b in editorTextBytesBE)
          {
               Console.Write("[{0}]", b);
           }
               Console.WriteLine();
  
          String decodedString = UnicodeEncoding.BigEndianUnicode.GetString(editorTextBytesBE);
  
          Console.WriteLine();
          Console.WriteLine("Decoded bytes:");
          Console.WriteLine(decodedString);
  
          // inserting UTF-16BE BOM marker, which eases recognition for any editor
          byte[] editorTextBytesToSend = { 0xfe, 0xff };
          editorTextBytesToSend.CopyTo(editorTextBytesBE, 2);
  
  
          File.WriteAllText(fileName, decodedString);
  
          Console.WriteLine("Uploading {0} to {1} ...", fileName, myURL);
          // Upload the file to the URL
          editorTextBytesBE =  myWebClient.UploadFile(myURL, "PUT", fileName);
  </code></pre>
  
  <p>I haven't been able to find anything to switch to big endian, but I've seen some examples (which I couldn't get working alas) to switch TO UTF-8. Would much appreciate any help, examples, or links to get the code to UTF-16BE. </p>