The objective:
Create a marker in a HTML file for the "end" of the file in C#
I am iterating through a file in C# and taking the table values and storing them in a database. The file grows and grows everyday, the results being added in are just being appended to the report.
In C# I have a StreamReader
that iterates through each file and places values in a list for insert into a SQL database.
string file_path = @"C:\This\Is\The\Way";
string[] files = Directory.GetFiles(file_path, "*.html", SearchOption.TopDirectoryOnly);
List<string> file_contents = new List<string>();
int* file_pointer; // Create my pointer
foreach(string file in files)
{
using (StreamReader reader = new StreamReader(file))
{
string line = string.Empty;
while ((line = reader.ReadLine()) != null)
{
// Remove <td> and </td>
line = line.Substring(4);
line = line.Remove(4);
// store in a list
file_contents.Add(line);
// Would I leave a pointer here ? then just keep moving it after every line until the end?
// The thought for line.Contains("</td>") is that the last line,
// </html> will just be moved to the end and the pointer wont show new rows.
// this way it goes to last </td>
if(line.Contains("</td>")
file_pointer += 1;
}
}
foreach (string item in file_contents)
// SQL insert, not implemented yet
file_contents.Clear();
}
"Test" Data
<table>
<tr>
<th>Test Unique to File</th>
<th>Data Point A Unique to Test</th>
<th>Data Point B Unique to Test</th>
<th>Time Taken</th>
<th>Pass/Fail</th>
</tr>
<tr>
<td>Test A Run</td>
<td>Data Point A</td>
<td>Data Point B</td>
<td>213 seconds</td>
<td>Pass</td>
</tr>
<tr>
<td>Test B Run</td>
<td>Data Point A</td>
<td>Data Point B</td>
<td>3333 seconds</td>
<td>Fail</td>
</tr>
<tr>
<td>Test C Run</td>
<td>Data Point A</td>
<td>Data Point B</td>
<td>12 seconds</td>
<td>Pass</td>
</tr>
</table>
The goal is for once the html report is parsed & inserted into the database, a position is marked in that html file. Then say tomorrow, another 6 rows are added. Instead of iterating through the whole file and just verifying that everything about to be inserted isn't a duplicate, we can just pick up where we left off.
I'm not sure the best way to go about this and would appreciate some guidance.
Question: Would creating a pointer at the end of every be the best bet?