C# 1256 file encoding

Posted on 2006-04-17
Last Modified: 2011-04-14
I am facing an encoding problem.
I want to write information to a file ( Arabic Letters ( windows-1256 ) ), but the letters are written in UTF-8 , here is the code :

FileStream afile = new FileStream ("school_db.sql", FileMode .OpenOrCreate);
StreamWriter sw = new StreamWriter (afile);
string test = "شكرا على المساعدة ";
sw.Close ();

So I want to convert the variable :' test' to windows-1265 befor writing it to the file.
Thank you for your help

Question by:ad-sol
    LVL 14

    Accepted Solution

    You are pointing at this?

    System.Text.Encoding enc = System.Text.Encoding.GetEncoding(1256);
    System.IO.StreamWriter sw = new System.IO.StreamWriter("c:\test", false, enc);

    Author Comment

    Yes, it is working now,
    Thank you PockyMaster

    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

    Join & Write a Comment

    Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    731 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

    18 Experts available now in Live!

    Get 1:1 Help Now