Step 3 – Create web server based files for the tool
Now with the both pre and post check files created, let's create a web framework to perform web-based pre/post check for the files. We need to create a web page in which our current log files are visible as pre and post files, and we can select the precheck file and its relevant postcheck file for comparison. As we know that we cannot use HTML or browser languages to fetch information about any files from the server, we need to use some backed web language to perform this function for us. We take advantage of ASP and VB.NET to create the web page to display the already created log files for selection and comparison.
The backend code for selectfiles.aspx is as follows (this is to display the files from the log directory on a browser):
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="selectfiles.aspx.vb" Inherits="selectfiles" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" method="post" action="comparefiles.aspx" >
<div>
<%response.write(xmystring.tostring())%>
</div>
<input type="submit" value="Submit">
</form>
<br><br><br>
</body>
</html>
The VB.NET backend code, to fill in the values on the preceding .aspx page selectfiles.aspx.vb, is as follows:
Imports System.IO
Partial Class selectfiles
Inherits System.Web.UI.Page
Public xmystring As New StringBuilder()
Public tableval As New Hashtable
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim precheck As New List(Of String)
Dim postcheck As New List(Of String)
Dim prename = New SortedList
Dim postname = New SortedList
Dim infoReader As System.IO.FileInfo
Dim rval as Integer
rval=0
xmystring.Clear()
Dim xval As String
Dim di As New DirectoryInfo("C:\iistest\logs\")
Dim lFiles As FileInfo() = di.GetFiles("*.txt")
Dim fi As System.IO.FileSystemInfo
Dim files() As String = IO.Directory.GetFiles("C:\iistest\logs\", "*.txt", SearchOption.TopDirectoryOnly)
xmystring.Append("<head><style type='text/css'>a:hover{background:blue;color:yellow;}</style></head>")
xmystring.Append("<fieldset style='float: left;width: 49%;display: inline-block;box-sizing: border-box;'>")
xmystring.Append("<legend>Pre check files (Sorted by Last Modified Date)</legend>")
For Each fi In lFiles
rval=rval+1
tableval.add(fi.LastWriteTime.ToString()+rval.tostring(),fi.Name)
'infoReader = My.Computer.FileSystem.GetFileInfo(file)
If (fi.Name.Contains("pre")) Then
precheck.Add(fi.LastWriteTime.ToString()+rval.tostring())
Else
postcheck.Add(fi.LastWriteTime.ToString()+rval.tostring())
End If
Next
precheck.Sort()
postcheck.Sort()
xval = ""
Dim prekey As ICollection = prename.Keys
Dim postkey As ICollection = postname.Keys
Dim dev As String
Dim fnameval as String
For Each dev In precheck
infoReader = My.Computer.FileSystem.GetFileInfo(tableval(dev))
fnameval="http://localhost/test/logs/"+Path.GetFileName(tableval(dev))
xval = "<input type = 'radio' name='prechecklist' value='C:\iistest\logs\" + tableval(dev) + "' required><a href='" & fnameval & "' target='blank'>" & tableval(dev) & "</a> ( <b>" & dev.Substring(0,dev.LastIndexOf("M")).Trim() + "M</b>)<br>"
xmystring.Append(xval)
Next
xmystring.Append("</fieldset>")
xmystring.Append("<fieldset style='float: right;width: 49%;display: inline-block;box-sizing: border-box;'>")
xmystring.Append("<legend>Post check files (Sorted by Last Modified Date)</legend>")
For Each dev In postcheck
fnameval="http://localhost/test/logs/"+tableval(dev)
xval = "<input type = 'radio' name='postchecklist' value='C:\iistest\logs\" + tableval(dev) + "' required><a href='" & fnameval & "' target='blank'>" & tableval(dev) & "</a> ( <b>" & dev.Substring(0,dev.LastIndexOf("M")).Trim() + "M</b>)<br>"
xmystring.Append(xval)
Next
xmystring.Append("</fieldset>")
End Sub
End Class
This code is used to fetch the files from the log directory, and based on their filenames, they are divided into either precheck files or postcheck files. Also, the files are ordered in chronological order for easy selection during the comparison process.
Let's see the output of this page now: