Divya123 0 Newbie Poster

I have written code for an application and now i need to put some code in class file and then by refererring to that class file need to again write this code
What code to put in the class file
the code which i have done is like this

Imports System.IO
Imports System.Data
Imports System.Text




Public Class WebForm1
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblFromDate As System.Web.UI.WebControls.Label
    Protected WithEvents btnGet As System.Web.UI.WebControls.Button
    Protected WithEvents txtToDate As System.Web.UI.WebControls.TextBox
    Protected WithEvents lblTodate As System.Web.UI.WebControls.Label
    Protected WithEvents txtFromDate As System.Web.UI.WebControls.TextBox
    Protected WithEvents CalToDate As System.Web.UI.WebControls.Calendar
    Protected WithEvents CalFromDate As System.Web.UI.WebControls.Calendar
    Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
    Protected WithEvents Button1 As System.Web.UI.WebControls.Button
    Protected WithEvents Button2 As System.Web.UI.WebControls.Button
    Protected WithEvents Button3 As System.Web.UI.WebControls.Button

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        CalFromDate.Visible = False
        CalToDate.Visible = False
        txtToDate.Text = caltodate.SelectedDate
        txtFromDate.Text = CalFromDate.SelectedDate
    End Sub


    Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click
        Try
            Dim strpath As String = Server.MapPath("\logfiles")
            Dim Directory As New DirectoryInfo(strpath)
            Dim aryfile As IO.FileInfo() = Directory.GetFiles("logfile*.")
            Dim logfile As IO.FileInfo
            Dim array As New ArrayList

            Dim table As DataTable = CreateTable()
            Dim row As DataRow
            For Each logfile In aryfile
                Dim strsub As String
                'rethink on the hardcoded size
                strsub = logfile.Name.Substring(7)
                Dim dt As DateTime
                Dim iYear As Integer = System.Convert.ToInt32(strsub.Substring(0, 4))
                Dim iMonth As Integer = System.Convert.ToInt32(strsub.Substring(4, 2))
                Dim iDay As Integer = System.Convert.ToInt32(strsub.Substring(6, 2))
                dt = New DateTime(iYear, iMonth, iDay)

                If dt >= txtFromDate.Text And dt <= txtToDate.Text Then
                    array.Add(logfile.Name)

                End If
            Next
            Dim item As String
            For Each item In array
                Dim stream_reader As New IO.StreamReader(item)

                Dim OpenPath As String, contents As String
                Dim tabSize As Integer = 4
                Dim arInfo As String()
                Dim line As String
                'Create new DataTable. 

                Try
                    'Get a StreamReader class that can be used to read the file 
                    Dim objStreamReader As StreamReader
                    objStreamReader = File.OpenText(item)
                    While objStreamReader.Peek <> -1

                        line = objStreamReader.ReadLine()

                        'line.Remove(0, 6)
                        'objStreamReader.Close()
                        'line.Replace("ewline", "")
                        contents = line.Replace(("").PadRight(tabSize, " "c), "" & Chr(9) & "")
                        If (contents.Length > 6) Then
                            contents = contents.Remove(0, 6)
                        End If
                        If contents.StartsWith("Exception") Then
                            Dim textdelimiter As Char() = {":"}
                            arInfo = contents.Split(textdelimiter)
                            row = table.NewRow
                        Else
                            ' define which character is seperating fields 
                            Dim textdelimiter As Char() = {"["}
                            arInfo = contents.Split(textdelimiter)
                            row = table.NewRow()
                        End If
                        For i As Integer = 0 To arInfo.Length
                            ' Dim i As Integer = 0
                            If i < arInfo.Length Then
                                row(i) = arInfo(i).ToString()
                            End If


                            If i = 2 Then
                                Exit For
                            End If
                        Next

                        table.Rows.Add(row)

                    End While


                    'objStreamReader.Close()
                    DataGrid1.DataSource = table
                    DataGrid1.DataBind()
                Catch ex As Exception
                    'gfgdfg
                End Try




            Next



        Catch exc As System.IO.FileNotFoundException
            ' Ignore this error.
        Catch exc As Exception
            ' Report other errors.
            'MsgBox(exc.Message, MsgBoxStyle.Exclamation, "Read " & _
            '    "Error")
        End Try




    End Sub
    Private Function CreateTable() As DataTable
        Try
            Dim table As New DataTable
            ' Declare DataColumn and DataRow variables. 
            Dim column As DataColumn
            ' Create new DataColumn, set DataType, ColumnName 
            ' and add to DataTable. 
            column = New DataColumn
            column.DataType = System.Type.[GetType]("System.String")
            column.ColumnName = "Date"
            table.Columns.Add(column)
            ' Create second column. 
            column = New DataColumn
            column.DataType = Type.[GetType]("System.String")
            column.ColumnName = "Exception"
            table.Columns.Add(column)
            column = New DataColumn
            column.DataType = System.Type.[GetType]("System.String")
            column.ColumnName = "DEBUG"
            table.Columns.Add(column)
            Return table
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Function



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        CalFromDate.Visible = True

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        CalToDate.Visible = True
    End Sub

End Class

can anyone help me regarding thsi

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.