Thank you for viewing the source code to
MyLinks.aspx.
If you see any bugs in this code, please
Let me know! I will be
happy to correct the problem.
Imports System.IO
Partial Class MyLinks
Inherits System.Web.UI.Page
Private fileName As String = "DDLinks.txt"
Private relPath As String = "Text/"
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Try
Dim strPass = ConfigurationManager.AppSettings("strAdminPassword")
If Me.txtComments.Text <> "" And Me.txtPassword.Text = strPass Then
Dim path As String = Server.MapPath(relPath) & "\"
Dim fs As New FileStream(path & fileName, FileMode.Append, FileAccess.Write)
'declaring a FileStream and creating a word document file named file with
'access mode of writing
Dim s As New StreamWriter(fs)
'creating a new StreamWriter and passing the filestream object fs as argument
's.BaseStream.Seek(0, SeekOrigin.End)
'the seek method is used to move the cursor to next position to avoid text to be
'overwritten
Dim dtNow As New Date
dtNow = Date.Now
s.WriteLine(DALC.ReverseLines("<b>" & dtNow.ToShortDateString & "</b><br/>" & Me.txtComments.Text & vbCrLf))
s.Close()
'closing the file
' // Clear out the text...
Me.txtComments.Text = ""
ElseIf Me.txtComments.Text <> "" And Me.txtPassword.Text <> strPass Then
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "clientScript", "<script language='JavaScript'>alert('Incorrect Password!');</script>")
End If
' // Display the new comments
Call DisplayLinks()
Catch ex As Exception
Me.ltChar.Controls.Add(New LiteralControl("An Error has Occurred: " & ex.Message))
Call EMailer.SendMail("", "", "Error in MyLinks.aspx", ex.Message)
End Try
End Sub
Private Sub DisplayLinks()
' Me.ltChar.Text = ""
Try
Dim path As String = Server.MapPath(relPath) '& "\"
'declaring a FileStream to open the file named file.doc with access mode of reading
Dim fs As New FileStream(path & fileName, FileMode.Open, FileAccess.Read)
Dim d As New StreamReader(fs)
' // Build a string with the output
' // We are reversing the order of the items of the file
' // and this is the easiest way.
Dim strChat As String = ""
While d.Peek() > -1
'peek method of StreamReader object tells how much more data is left in the file
strChat = d.ReadLine() & "<br/>" & vbCrLf & strChat
End While
d.Close()
'displaying text from doc file in the Panel
Me.ltChar.Controls.Add(New LiteralControl(strChat))
Catch ex As Exception
Me.ltChar.Controls.Add(New LiteralControl("An Error has Occurred: " & ex.Message))
Call EMailer.SendMail("", "", "Error in MyLinks.aspx", ex.Message)
End Try
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Call DisplayLinks()
End If
End Sub
End Class
Copyright © 1984-2024 Dennis Day
All rights reserved