Streamwriter + WriteLine UTF8

Posted on 2009-04-22
Last Modified: 2012-05-06
I am using a streamwriter object to write lines of text to a text file, the problem is when the file is being received by a third party they are saying it is in UTF8 format, I need it to be in ascii, how do I change it?
Question by:rocky050371
    1 Comment
    LVL 39

    Accepted Solution

    When you create the StreamWriter, you can give it an encoding, that should do the trick:

    '// create sw with special enc '
    StreamWriter sw = new StreamWriter(File.Open("path-to-file", FileMode.Open), Encoding.ASCII);
    ' thats it '

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now