You can use below Helper function for your requirement
for this namespace system.Data Required
//Add following namespace in namespace section
using system.Data;
//below is the helper function which will take input as a path of your file and will return you datatable
public DataTable ConvertToDataTable(string path)
{
string s = string.Empty;
string[] stringarry=System.IO.File.ReadAllLines(path);
System.Data.DataTable data = new System.Data.DataTable();
data.Columns.Add("Type", typeof(string));
data.Columns.Add("Category", typeof(string));
data.Columns.Add("Grade style", typeof(string));
data.Columns.Add("Random answers", typeof(string));
data.Columns.Add("Randomize Options", typeof(string));
data.Columns.Add("Question", typeof(string));
data.Columns.Add("A", typeof(string));
data.Columns.Add("B", typeof(string));
data.Columns.Add("C", typeof(string));
data.Columns.Add("D", typeof(string));
data.Columns.Add("E", typeof(string));
data.Columns.Add("Correct", typeof(string));
data.Columns.Add("Points", typeof(string));
data.Columns.Add("CF", typeof(string));
data.Columns.Add("WF", typeof(string));
data.AcceptChanges();
DataRow dr=null;
foreach (string st in stringarry)
{
if(!string.IsNullOrEmpty(st))
{
string[] splitarray=st.Split(':');
if (splitarray != null && splitarray.Length > 1)
{
if (splitarray[0].ToUpper() == "(Type)".ToUpper())
{
dr = data.NewRow();
dr["Type"] = splitarray[1];
}
else if (splitarray[0].ToUpper() == "(Category)".ToUpper())
{
dr["Category"] = splitarray[1];
}
else if (splitarray[0].ToUpper() == "(Grade style)".ToUpper())
{
dr["Grade style"] = splitarray[1];
}
else if (splitarray[0].ToUpper() == "(Random answers)".ToUpper())
{
dr["Random answers"] = splitarray[1];
}
else if (splitarray[0].ToUpper() == "(Randomize Options)".ToUpper())
{
dr["Randomize Options"] = splitarray[1];
}
else if (splitarray[0].ToUpper() == "(Question)".ToUpper())
{
dr["Question"] = splitarray[1];
}
else if (splitarray[0].ToUpper() == "(A)".ToUpper())
{
dr["A"] = splitarray[1];
}
else if (splitarray[0].ToUpper() == "(B)".ToUpper())
{
dr["B"] = splitarray[1];
}
else if (splitarray[0].ToUpper() == "(C)".ToUpper())
{
dr["C"] = splitarray[1];
}
else if (splitarray[0].ToUpper() == "(D)".ToUpper())
{
dr["D"] = splitarray[1];
}
else if (splitarray[0].ToUpper() == "(E)".ToUpper())
{
dr["E"] = splitarray[1];
}
else if (splitarray[0].ToUpper() == "(Correct)".ToUpper())
{
dr["Correct"] = splitarray[1];
}
else if (splitarray[0].ToUpper() == "(Points)".ToUpper())
{
dr["Points"] = splitarray[1];
}
else if (splitarray[0].ToUpper() == "(CF)".ToUpper())
{
dr["Correct"] = splitarray[1];
}
else if (splitarray[0].ToUpper() == "(WF)".ToUpper())
{
dr["WF"] = splitarray[1];
data.Rows.Add(dr);
}
}
}
}
data.AcceptChanges();
return data;
}
:) Happy Coding.
Please ask any query if you have in above code.
Please mark it as solution if it helps you.