Imports System Imports System.ComponentModel Imports System.IO Imports System.Web Imports System.Web.UI Namespace LozinskiWebScript ")> _ Public Class Updated Inherits System.Web.UI.WebControls.WebControl '#Class: LozinskiUpdated.vb - Version 1.0 '# '# This .NET Web Control will automatically determine and print an '#"updated" image and/or the date a specified file was last "updated". '# '#INSTALLATION INSTRUCTIONS: '# 1) Set the value for UPDATED_IMAGE_URL to be the URL to the '#"updated" image you wish to have displayed. '# 2) Compile this VB .NET code and move the resulting dll file into your web project's "bin" directory. '# 3) In the aspx page you wish to have this control run, add in the appropriate "Register" directive. '# Example: '# <%@ Register TagPrefix="Lozinski" Namespace="Updated.LozinskiWebScript" Assembly="Updated" %> '# 4) Add the control's tag to your ASPX page wherever you would like '# the notification that a file has been updated. '# '#TO ADD THE CONTROL TO YOUR VISUAL STUDIO TOOLBOX: '# 1) Select "File | New Project" '# 2) Make sure "VB Class" is slected. Change the default name '# to "RandomImage2.vb", select the location, and '# select "close solution". '# 3) Click "ok". '# 3) Copy and paste this code into your new class file. '# 4) Compile this file. '# 5) Open up your web project with the aspx forms you would like '# to have the random images on. '# 6) Select "Project | Add Reference" '# 7) Click the "browse" button. Find the location of the '# LozinskiRandomImage2.dll file, select the file, '# and click "ok". '# 8) You should now see it in your "solution explorer". '# 9) In the design view to any of your aspx web forms, right click '# within your toolbox and select "add/remove items". '# 10) Click "browse", select the LozinskiRandomImage2.dll '# file, and click "ok". '# 11) It should now be in your toolbox! Just drag and drop '# like any other tool. Enjoy! :) '# '#CONFIGURING: '# '# All the property values below can be set through the Visual Studio '# interface when added as a web control to your project. '# '# 1) "FileList" : is required. This is the actual file '#or files to test for their last modification date. This parameter '#should be the FULL OPERATING SYSTEM PATH, AND NOT A URL!!! The file(s) '#to test can be ANY file. '# To test multiple files, separate each file with a pipe "|" character. This is especially '#useful for HTML "frame" pages. That is, suppose you have a table of contents page and the main '#information page, and you want "updated" printed whenever either one of those two pages is updated. '# EXAMPLES: '# F:/Inetpub/wwwroot/scripts/some_file.aspx '# F:/Inetpub/wwwroot/images/myself.jpg|F:/Inetpub/wwwroot/index.html '# F:/Inetpub/wwwroot/default.asp '# '# Example tag below given the above "Register": '# '# '# 2) "DayDifference" '# The number of days previous to today's date the files in "FileList" should have been updated '# to have the "updated" info displayed. Specifying "-1" means no limit and the '# "updated" info will always be printed. '# EXAMPLES: '# i) If "today" is the 27th, the file "test.html" was updated on the 21st, and DayDifference '#is specified to be 4, the "updated" would NOT be displayed because test.html was not '#updated within the last 4 days. '# ii) If "today" is the 27th, the file "test.html" was updated on the 21st, and DayDifference '#is specified to be 7, the "updated" WOULD be displayed because test.html was '#updated within the last 7 days. '# iii) If "today" is the 27th, the file "test.html" was updated on the 21st, and DayDifference '#is specified to be -1, the "updated" WOULD always be displayed. '# '# 3) "DisplayMode" '# Can only be one of three integer values: '# 0 : Print both the "updated" image and the textual date '# 1 : Print the "updated" image only '# 2 : Print the textual date only of the file's last update '# '#EXAMPLE USES (the last two should testing multiple files) '# '# '# '# '# '#REQUIREMENTS: '# 1) Windows 2000 Server or later '# 2) IIS 5.0 or later '# 3) .NET Framework >= 1.1 '# '#LICENSE: '# Finally, this "basic" code is free, and comes with absolutely NO '#warranties, either expressed or implied. Feel free to do what you want '#with it. Feel free to build upon it. If you did not get this code '#from http://www.davelozinski.com, you don't have the original. '# '#REVISION HISTORY: '# 08/05/05 Original Version '# '#CONTACT INFORMATION: '# http://www.davelozinski.com/cgi-bin/email_lozinski.pl '######################################################## '# '#the URL to the "updated" image you wish to have displayed. Private UPDATED_IMAGE_URL = "/gfx/updated.gif" '#The default value for the property "DayDifferent" Private days As Integer = 30 '#The default value for the property "DisplayMode" Private mode As Integer = 0 '############################################################## '#### NOTHING FROM HERE DOWN SHOULD NEED TO BE CONFIGURED. #### '############################################################## Private files As String = "" Private file_arr() As String Private x As Integer = 0 _ Property FileList() As String Get Return files End Get Set(ByVal Value As String) If (Value = "") Then Throw New ArgumentException("""FileList"" is required.") Else file_arr = Split(Value, "|") '#Check to make sure the files given actually exist. For x = 0 To UBound(file_arr) If (Not File.Exists(file_arr(x))) Then Throw New FileNotFoundException("The file " & file_arr(x) & " does not exist.") Exit For End If Next files = Value End If End Set End Property _ Property DayDifference() As Integer Get Return days End Get Set(ByVal Value As Integer) If (VarType(Value) <> VariantType.Integer) Then Throw New ArgumentException("The value for ""DayDifference"" must be an integer.") ElseIf (Value < -1) Then Throw New ArgumentOutOfRangeException("The value for ""DayDifference"" must be greater than or equal to -1.") Else days = Value End If End Set End Property _ Property DisplayMode() As Integer Get Return mode End Get Set(ByVal Value As Integer) If (VarType(Value) <> VariantType.Integer) Then Throw New ArgumentException("The value for ""DisplayMode"" must be an integer.") ElseIf (Value < 0 OrElse Value > 2) Then Throw New ArgumentOutOfRangeException("The value for ""DayDifference"" must either be 0 (zero), 1 (one), or 2 (two).") Else mode = Value End If End Set End Property Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter) Dim updated_date As Date Dim filedate As Date If (file_arr Is Nothing) Then Throw New ArgumentNullException("The parameter ""FileList"" is required.") Else For x = 0 To UBound(file_arr) updated_date = DateValue(File.GetLastWriteTime(file_arr(x)).Month & "/" & File.GetLastWriteTime(file_arr(x)).Day & "/" & File.GetLastWriteTime(file_arr(x)).Year) filedate = DateValue(Today.Month & "/" & Today.Day & "/" & Today.Year) If (days = -1 OrElse (DateDiff("d", updated_date, filedate) < days)) Then If (mode = 0 OrElse mode = 1) Then '#Print the "updated" image output.Write("") End If If (mode = 0 OrElse mode = 2) Then '#Print the "updated" date output.Write(updated_date.ToShortDateString) End If Exit For '#At least one of the files has been updated. No reason to check the rest. End If Next End If End Sub End Class End Namespace