title: Convert UTF-16 text to another encoding (Windows-1250)
body: <p>I have a text in a variable, <strong>text</strong>, encoded in the default (UTF-16) encoding. I would like to change it to <a href="http://en.wikipedia.org/wiki/Windows-1250" rel="nofollow">Windows-1250</a>. I have:</p>
  
  <pre><code>public static string EncodeToWin1250(string text)
  {
      Encoding unicode = Encoding.Unicode;
      Encoding win1250 = Encoding.GetEncoding(1250);
  
      byte[] unicodeBytes = unicode.GetBytes(text);
      byte[] win1250Bytes = Encoding.Convert(unicode, win1250, unicodeBytes);
  
      char[] win1250Chars = new char[win1250.GetCharCount(win1250Bytes, 0, win1250Bytes.Length)];
      win1250.GetChars(win1250Bytes, 0, win1250Bytes.Length, win1250Chars, 0);
      text = new string(win1250Chars);
      return text;
  }
  </code></pre>
  
  <p>but so far it doesn't work.</p>
  
  <p>How do I fix this problem?</p>
  
  <p>I am returning the string as a file:</p>
  
  <pre><code>[...]
  result = BLL.DataExchange.MoneyS3.MoneyS3Export.EncodeToWin1250(result);
  Context.Response.Clear();
  Context.Response.AddHeader("Content-Disposition", "attachment; filename=invoicesIssued.xml");
  Context.Response.ContentType = "application/octet-stream";
  Context.Response.BufferOutput = false;
  Context.Response.Write(result);
  Context.Response.Flush();
  Context.Response.Close();
  </code></pre>