Hello all,
I've a problem to sort and display text file based on specific keyword such as "SUCCESSFUL" or "FAILED".
I've managed to create a block of code that can retrieve and then display the text file using StreamReader as well as GridView.
Now, my next mission is to sort the contents inside the text file and only display line that contains either the word "SUCCESSFUL" or "FAILED".
Below is my .aspx.vb file:
Imports System
Imports System.IO
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'To find subdirectories with a specific pattern/WILD CARD
'ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_vbcn/html/c9265fd1-7483-4150-8b7f-ff642caa939d.htm
'Me.ListBox1.Items.Clear()
' Dim path As String = "\\" + TextBox1.Text + "\E$"
Dim path As String = "C:\Users\hairudin\Desktop\azrin"
Dim searchPattern As String = "*gvw*.txt"
For Each value As String In My.Computer.FileSystem.GetFiles(path, FileIO.SearchOption.SearchAllSubDirectories, searchPattern)
ListBox1.Items.Add(value)
'TextBox1.Text = "Found"
Dim objStreamReader As New StreamReader(value)
Dim arrText As New ArrayList
Do While objStreamReader.Peek() >= 0
arrText.Add(objStreamReader.ReadLine)
Loop
objStreamReader.Close()
GridView1.DataSource = arrText
GridView1.DataBind()
Next
' Imports System.Data
' Imports System.Xml
' Partial Class _Default
' Inherits System.Web.UI.Page
' Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) HandlesMe.Load
' If Not IsPostBack Then
' Dim ds As New DataSet
' ds.ReadXml(MapPath(value))
' Xml1.Document = New XmlDataDocument(ds)
' Xml1.TransformSource = "QA.xslt"
' End If
'Public Shared Function FormatXml(ByVal xmlDoc As XmlDocument) As String
' Dim sb As New StringBuilder()
' Using stringWriter As New StringWriter(sb)
' Using xmlTextWriter As New XmlTextWriter(stringWriter)
' xmlTextWriter.Formatting = Formatting.Indented
' xmlDoc.WriteTo(xmlTextWriter)
' End Using
' End Using
' Return sb.ToString()
'End Function
End Sub
Protected Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
End Sub
Protected Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
'Protected Sub textBoxContents_TextChanged(sender As Object, e As EventArgs) Handles textBoxContents.TextChanged
'End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
Here is my .aspx file:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %><%@ Import Namespace="System.Data" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"><title>SQL Verify QA</title><style type="text/css">
.auto-style1
{
width: 974px;
}</style></head><body><form id="form1" runat="server"><div></div> <table bgcolor="White" style="font-family: Arial, Helvetica, sans-serif; color: #800080;" align="center"><tr><td class="auto-style1">
Server Name: <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Height="26px" Text="Submit" /><br /></td></tr><tr><td class="auto-style1"> <asp:ListBox ID="ListBox1" runat="server" Height="28px"></asp:ListBox><br /><br />
Result: <br /></td></tr><tr> <td class="auto-style1"><div><asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#0000CC" RowHeaderColumn="2" Style="margin-left: 0px" Width="1045px" AllowSorting="True" ><EditRowStyle BorderStyle="Solid" /><HeaderStyle BorderStyle="Solid"/></asp:GridView> </div></td></tr></table></form> </body></html>Can anyone help me on this sorting mechanism?
Thanks.