Cleveland Renaissance Hotel
Ballroom B
Cleveland, OH 44113
(216) 696-5600
Subject Content
Sub FilePurge()
Static dtLastPurgeTime As DateTime
Dim dtNow As DateTime
Dim intCounter As Integer
Dim Files() As String
Dim strGUID As String, strTXTName As String
While True
strGUID = System.Guid.NewGuid.ToString
strTXTName = "C:\Temp\STB_" & strGUID & ".TXT"
'Create a uniquely named .TXT file
Dim swTXT As StreamWriter
swTXT = File.AppendText(strTXTName)
swTXT.WriteLine(strGUID)
swTXT.Close()
'Wait 2 seconds before proceeding
System.Threading.Thread.Sleep(2000)
dtNow = Now
Dim lTimeDiff As Long = DateDiff(DateInterval.Hour, dtLastPurgeTime, dtNow)
If lTimeDiff > 24 And Now.Hour = 22 Then 'Check if last purge was more then 24 hours ago and current hour is 10PM
'Purge *.TXT files
Files = Directory.GetFiles("C:\Temp", "STB_*.TXT")
For intCounter = Files.GetLowerBound(0) To Files.GetUpperBound(0)
If DateDiff(DateInterval.Minute, File.GetCreationTime(Files(intCounter)), dtNow) > 30 Then 'Purge only if file is older than 30 minutes
File.Delete(Files(intCounter))
End If
Next intCounter
'Update Purge Time
dtLastPurgeTime = Now()
End If
End While
Error_Handler:
Resume Next 'If an error occured while deleting a file, skip it this iteration and move to the next file
End Sub
The Virtual Directory is now configured as an Application and the ASP.Net should work as expected. If not there maybe a conflict with the settings in the Machine.config file.