Change file encoding

qlwik

Client
Регистрация
03.04.2013
Сообщения
207
Благодарностей
5
Баллы
18
Hi, is there any way to convert any file for example from windows-1251 to utf-8 with zennoposter, for example with C#? windows-1251 is only example, this might be different encoding, just don't suggest me notepad++, it must be integrated in template.
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 771
Благодарностей
1 184
Баллы
113

qlwik

Client
Регистрация
03.04.2013
Сообщения
207
Благодарностей
5
Баллы
18
Ok I got below code from stackoverflow:

C#:
using System;
using System.IO;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        string inputFile = @"C:\file.txt";      // Path to your input file
        string outputFile = @"C:\file2.txt";   // Path to your output file
        
        ConvertEncoding(inputFile, outputFile);
        
        Console.WriteLine("Conversion complete.");
    }

    static void ConvertEncoding(string inputFilePath, string outputFilePath)
    {
        using (StreamReader reader = new StreamReader(inputFilePath, Encoding.GetEncoding("iso-8859-1")))
        {
            using (StreamWriter writer = new StreamWriter(outputFilePath, false, Encoding.UTF8))
            {
                writer.Write(reader.ReadToEnd());
            }
        }
    }
}
But it throw a lot of errors, for example:
Compiling code of Error in action "CS1003" "Syntax error, '(' expected". [Row: 1; Column: 7]
What is wrong?
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 771
Благодарностей
1 184
Баллы
113
You can not just copy any code anywhere and expect it to work, man.
You need to change it as per your requirements.
This is the code needed for you, but you still have to change variables to yours.
I have not tested though.

C#:
using (StreamReader reader = new StreamReader(inputFilePath, Encoding.GetEncoding("iso-8859-1")))
{
    using (StreamWriter writer = new StreamWriter(outputFilePath, false, Encoding.UTF8))
    {
        writer.Write(reader.ReadToEnd());
    }
}
 

qlwik

Client
Регистрация
03.04.2013
Сообщения
207
Благодарностей
5
Баллы
18
I saw Your code, but I don't know how to insert input and output files to code, because I don't know C#, can You help me?
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)