You're here: Snippet Directory » Microsoft .NET (154)
Language:

Retrieving file properties

Language: English
Programming Language: VB.NET
Published by: Dennis Pallett [not registered]
Last Update: 5/9/2006
Views: 795

Description

Retrieve a list of files and write out certain properties. (VB.NET)

Code

1 <%@Page Language="VB" %> 2 <%@ Import Namespace="System.IO" %> 3 4 <script language="VB" runat="server"> 5 Sub Page_Load(sender As Object, e As EventArgs) 6 Dim strFiles As String() ' array to hold files 7 Dim objFile As System.IO.FileInfo ' File object 8 Dim i As Integer 9 10 ' call the GetFiles method to retrieve an array of files 11 ' Server.MapPath("/") is your webroot folder. 12 strFiles = System.IO.Directory.GetFiles(Server.MapPath("/"),"*.*") 13 14 ' loop thru the array 15 For i = 0 To strFiles.Length - 1 16 'Create a "FileInfo" object for the file 17 objFile = New System.IO.FileInfo(strFiles(i)) 18 19 ' write out a few properties 20 ' visit http://docs.aspng.com/quickstart/aspplus/samples/classbrowser/vb/classbrowser.aspx 21 ' for a listing of all available properties and methods 22 23 Response.Write("Name : " &amp; objFile.Name.ToUpper() & "<br>") 24 Response.Write("Extension : " &amp; objFile.Extension.ToUpper() & "<br>") 25 Response.Write("Length : " &amp; Cstr(objFile.Length) &amp; "<br>") 26 Response.Write("Creation Date : " &amp; Cstr(objFile.CreationTime) & "<br>") 27 Response.Write("<br>") 28 Next 29 30 Response.End 31 End Sub 32 </script>

No comments avaiable

Add a comment

Name *  

Email (won't be displayed) *    

Website  

Comment *  

Sicherheitscode Security Code *    

RSS