Editing a Text File
Hi,
I'm trying to change the date in a text file to 14 days later once a button is clicked. The following is my code. It does not seem to do anything at all. Can someone please tell me what is going on? Thank you very much.
Imports System
Imports System.IO
Public Class WebForm1
Inherits System.Web.UI.Page
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Dim Days As Double
Dim IntervalType As DateInterval
Dim SecondDate As Date
IntervalType = DateInterval.Day
Days = 14
' Create an instance of StreamReader to read from a file.
Dim sr As StreamReader = New StreamReader("C:\Inetpub\wwwroot\CPS3\FIDELITY0921 2005.txt")
Dim sw As StreamWriter = New StreamWriter("C:\Inetpub\wwwroot\CPS3\FIDELITY0921 2005.txt")
Dim line, dt, newdate As String
Dim i As Integer
line = sr.ReadLine()
'Console.WriteLine(line)
line = sr.ReadLine()
' Add some text to the file.
sr.BaseStream.Seek(65, 71)
For i = 0 To 6
dt = sr.Read.ToString
If i = 0 Then
SecondDate = dt
Else
SecondDate = SecondDate & dt
End If
Next
newdate = DateAdd(IntervalType, Days, CDate(SecondDate))
sw.BaseStream.Seek(65, 71)
sw.Write(newdate)
sw.Close()
Catch
' Let the user know what went wrong.
Console.WriteLine("The file could not be read:")
End Try
End Sub
End Class
|