1-) C# RMOS - Ansi veya UTF8 belli değilse bu şekilde oku ansi to text ansi to string
kaynak : https://stackoverflow.com/questions/3825390/effective-way-to-find-any-files-encoding
private void Form1_Load(object sender, EventArgs e)
{
fileOku("ansi.txt");
fileOku("utf8.txt");
fileOku("ansi2.txt");
}
public void fileOku(string path)
{
var type = DetectFileEncoding(File.OpenRead(path));
string content = File.ReadAllText(path, type);
Console.WriteLine(content);
}
public Encoding DetectFileEncoding(Stream fileStream)
{
var Utf8EncodingVerifier = Encoding.GetEncoding("utf-8", new EncoderExceptionFallback(), new DecoderExceptionFallback());
using (var reader = new StreamReader(fileStream, Utf8EncodingVerifier,
detectEncodingFromByteOrderMarks: true, leaveOpen: true, bufferSize: 1024))
{
Encoding detectedEncoding;
try
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
}
detectedEncoding = Encoding.UTF8;//reader.CurrentEncoding.BodyName;
}
catch (Exception e)
{
// Failed to decode the file using the BOM/UT8.
// Assume it's local ANSI
detectedEncoding = Encoding.Default;// Encoding.GetEncoding("ISO-8859-9"); türkish
}
// Rewind the stream
fileStream.Seek(0, SeekOrigin.Begin);
return detectedEncoding;
}
}