if there is textBox and user input some text how to get the encoding?
If you are talking about the TextBox of .NET application such as Windows Forms there is no way to get encoding.
Encoding does not matter in the .NET application as string will be treated in unicode encoding.
You will probably have to consider encoding only when you get string form byte array (e.g., text file) or convert string to byte array. Please see the following sample which explains the above.
using System;
using System.Data.SqlClient;
using System.Text;
namespace ConsoleApp9
{
internal class Program
{
static void Main(string[] args)
{
string textBoxString = "Καλώς ήρθατε στην επίσκεψη";
// Create two different encodings.
Encoding unicode = Encoding.Unicode;
Encoding win1253 = Encoding.GetEncoding("windows-1253");
// Convert the string into a byte[].
byte[] unicodeBytes = unicode.GetBytes(textBoxString);
byte[] win1253Bytes = win1253.GetBytes(textBoxString);
foreach (byte b in unicodeBytes)
{
Console.Write($"[{b:x2}]");
}
Console.WriteLine("\n------------------------");
foreach (byte b in win1253Bytes)
{
Console.Write($"[{b:x2}]");
}
Console.WriteLine("\n------------------------");
}
}
}
Result