CP865 text encoding (a bit urgent).
-
Does anyone know how I can encode a string to a CP865 encoded text, (not for example Unicode or UTF8). What I am trying to do is to transfer a string content as an txt file with CP865 encodeing.
Response.ClearContent();
Response.AddHeader("Content-disposition", "Attachment;filename=Myfile.txt");
Response.ContentType = "text/plain";
Response.Write("This text shall have de Norwegian charset of the CP865 encoder");
Response.End();Thanks Thomas
-
Does anyone know how I can encode a string to a CP865 encoded text, (not for example Unicode or UTF8). What I am trying to do is to transfer a string content as an txt file with CP865 encodeing.
Response.ClearContent();
Response.AddHeader("Content-disposition", "Attachment;filename=Myfile.txt");
Response.ContentType = "text/plain";
Response.Write("This text shall have de Norwegian charset of the CP865 encoder");
Response.End();Thanks Thomas
You can convert to a specific codepage using the
Encoder
class:byte[] bytes = Encoding.GetEncoding(865).GetBytes("This text shall have de Norwegian charset of the CP865 encoder");
You may also need to specify the encoding in your response header. regards
-
You can convert to a specific codepage using the
Encoder
class:byte[] bytes = Encoding.GetEncoding(865).GetBytes("This text shall have de Norwegian charset of the CP865 encoder");
You may also need to specify the encoding in your response header. regards
Thanks, it worked great :) Here's a example of my final solution, if anyone else ever needs it.
int chunkSize = 10000;
MemoryStream ms = null;
int dataLeft = 0;
try
{
Response.ClearContent();
Response.AddHeader("Content-disposition", "Attachment;filename=Myfile.txt");
Response.ContentType = "text/plain";
byte[] bytes = System.Text.Encoding.GetEncoding(865).GetBytes("This text shall have de Norwegian charset of the CP865 encoder");dataLeft = bytes.Length;
ms = new MemoryStream(bytes);
while (dataLeft > 0 && Response.IsClientConnected)
{
byte[] currentChunk = new byte[chunkSize];
int currentChunkSize = ms.Read(currentChunk, 0, chunkSize);
Response.BinaryWrite(currentChunk);
dataLeft -= currentChunkSize;
currentChunk = null;
}
Response.End();
}
catch{}
finally
{
if (ms != null) ms.Close();
ms = null;
}