Is it possible to read rtf file and apply it to System.Data.DataTable? Old code has RichTextBox which I dont want to use it now. Is it possible to do it with Aspose.
public static System.Data.DataTable GetDataTableContentFromRtf(string filename)
{
var doc = new RichTextBox();
var idFieldFound = false;
doc.LoadFile(filename);
var content = doc.Text;
var rows = content.Split('\n');
if (rows.Length == 1)
return null;
var firstRow = true;
var dt = new System.Data.DataTable();
for (var i = 0; i < rows.Length; i++)
{
if (string.IsNullOrWhiteSpace(rows[i]))
continue;
var columns = rows[i].Split('\t');
if (firstRow)
{
for (var j = 0; j < columns.Count(); j++)
if (!string.IsNullOrEmpty(columns[j]))
{
if (columns[j] == ConfigConstants.UniqueFieldColumn) idFieldFound = true;
dt.Columns.Add(columns[j]);
}
if (!idFieldFound)
dt.Columns.Add(ConfigConstants.UniqueFieldColumn);
firstRow = false;
}
else
{
var row = dt.NewRow();
for (var k = 0; k < dt.Columns.Count - 1; k++) row[k] = columns[k];
if (!idFieldFound) row[ConfigConstants.UniqueFieldColumn] = Guid.NewGuid().ToString();
dt.Rows.Add(row);
}
}
return dt;
}