Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. CP865 text encoding (a bit urgent).

CP865 text encoding (a bit urgent).

Scheduled Pinned Locked Moved C#
tutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thomasa
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • T thomasa

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      T 1 Reply Last reply
      0
      • L Lost User

        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

        T Offline
        T Offline
        thomasa
        wrote on last edited by
        #3

        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;
        }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups