Use System.IO to determine file date to display 'new' image

This code tip reads in a directory of files, determines if the file date not older than 180 days and displays various image's. This builds a string and passes it to a Literal control.[code]Sub Page_Load(Sender as Object, E as EventArgs) ...

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 5
November 11, 2002
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement
This code tip reads in a directory of files, determines if the file date not older than 180 days and displays various image's. This builds a string and passes it to a Literal control.


<%@ Import Namespace="system.IO" %>
<%@ 
Register TagPrefix="Top" TagName="TopStuff" Src="toppage.ascx" %>
<%@ 
Register TagPrefix="Bottom" TagName="BottomStuff" Src="bottompage.ascx" %>
<
script language="vb" runat="server">

Sub Page_Load(Sender as Objectas EventArgs)
    
Dim dir As DirectoryInfo = New DirectoryInfo("d:webrootbigdogs")    
    
Dim files As FileInfo() = dir.GetFiles()
    
Dim count As Integer files.Length
    Dim i 
As Integer
    dim daFiles 
as string
For 0 To count 1
    Dim theDate 
As Integer DateDiff(DateInterval.Dayfiles(i).CreationTimeDate.Today)
        If 
theDate 180 Then
            daFiles 
daFiles "<li><img src=new.gif'><a href='" files(i).Name "'>" files(i).Name "</a></li>"
        
Else
            
daFiles daFiles "<li><a href='" files(i).Name "'>" files(i).Name "</a></li>"    
        
End If
Next

jokes
.Text "</ul>" daFiles
End Sub
</script>
<html>
    <head>
        <title>Big Dogs</title>
    </head>
    <body background="/images/pawsback.gif">
<Top:TopStuff TitleOfDemo=" list new Gif File" runat="server" />

<asp:Literal id="jokes" runat="server" />

<bottom:bottomstuff runat="server" />

    </body>
</html>

blog comments powered by Disqus
ASP.NET CODE ARTICLES

- How to Use the ListBox Control in ASP.NET 2.0
- How to Load XML Documents in ASP.NET 2.0
- DataGrid Code
- ASP.NET Guestbook
- User Controls and Client Side Scripting
- ASP.NET Programming with Microsoft's AS...
- ASP.NET Basics (part 3): Hard Choices
- ASP.NET Basics (part 2): Not My Type
- ASP.NET Basics (part 1): Nothing But .Net
- Directory Tree Browser
- How to get the confirmation of Yes/No from a...
- Complete example using custom errors and wri...
- Paging Certain # records per page .NET style
- General Methods of formatting and Subtractin...
- .NET LinkButton web control

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials