Print Page | Close Window

Dir() problem

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=5086
Printed Date: 28 March 2026 at 9:10pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Dir() problem
Posted By: Diep-Vriezer
Subject: Dir() problem
Date Posted: 17 August 2003 at 7:02am

Hi all,

I've got a little problem. How do I bind a repeater to all files with the extention *.jpg, *.gif, *.png in a directory using the Dir() function?

All other forums couldn't help me, Microsoft wouldn't respond, so you're my last hope!



-------------
Gone..



Replies:
Posted By: Diep-Vriezer
Date Posted: 27 August 2003 at 6:31am

Allright, no posts...

Well, let me explain it a bit more. I want all the jpg files in the Dir("C:\Path\*.jpg") to be displayed in either a datagrid or repeater.

Why is this so difficult? I mean, I'm a n00b, so if I don't understand things, that makes sence.



-------------
Gone..


Posted By: MorningZ
Date Posted: 27 August 2003 at 3:08pm

100 views and no answer....

i think its safe to assume that no one has tried to do with wht you are talking about.......   no need to "bump" up your post

i'd look elsewhere



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: masta-chief88
Date Posted: 28 August 2003 at 1:47am
Before going to forums, you should be looking up the System.IO class.  There are also tons of articles about displaying images in datagrids.


Posted By: Diep-Vriezer
Date Posted: 28 August 2003 at 7:56am
I know, but I don't want to add or remove data from a database, so the Dir() function is the most simple thing (I thougt..)

-------------
Gone..


Posted By: MorningZ
Date Posted: 28 August 2003 at 9:02am

i dont know what would be more involved than:

- Getting a list of the files with
Dim aLocalFiles As FileInfo() = (New DirectoryInfo(whatever directory)).GetFiles("*.jpg")

- Looping through that and put into an array

- Bind array to the control

seems like that would work



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Diep-Vriezer
Date Posted: 29 August 2003 at 5:25am
This looks like something , thanks!

-------------
Gone..


Posted By: Diep-Vriezer
Date Posted: 29 August 2003 at 7:42am
Type 'FileInfo()' is not defined

-------------
Gone..


Posted By: MorningZ
Date Posted: 29 August 2003 at 8:04am

i just pulled that from some code i did, it was just meant as a guide to some methods to look into, not the actual working code

 



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: MorningZ
Date Posted: 29 August 2003 at 8:42am

perhaps this 25 mins of my time can get you started :)
only thing i don't know how to do (and dont have time to investigate) is how to get mulitple types in that "GetFiles" method

<%@ Page Language="VB" %>
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Collections"%>
<!--
Stephen Gilboy aka MorningZ
Files in Directory >> DataGrid
-->
<script runat="server">
  Dim sVirtualDir As String = "/images2/" 'Virtual root to images
  Dim blnShowDebugMsg As Boolean = True 'Show the Debug messages

  Sub Page_Load(obj as object, e as eventargs )
 Dim sLocalDir, ThisFileName As String
 sLocalDir = Server.MapPath(sVirtualDir)

 If Not Directory.Exists(sLocalDir) Then
  Message.Text = "Directory """ & sVirtualDir & """ (" & sLocalDir & ") doesn't exist!!"
 Else
  Dim oLocalFile As FileInfo
  Dim aLocalFiles As FileInfo() = (New DirectoryInfo(sLocalDir)).GetFiles("*.gif")

  if aLocalFiles.Length > 0 then  'There are files to get, so continue
   Message.Text = "Total Files in Collection: " & aLocalFiles.Length
   List.DataSource = aLocalFiles
   List.DataBind()
  else
   Message.Text = "No files found"
  end if
 End If
 if blnShowDebugMsg then Message.Visible = True
  End Sub
</script>
<html>
<head>
</head>
<body>
<asp:label id="Message" runat="server" visible="false"/>
<form runat="server">
<asp:Datagrid id="List" runat="server"/>
</form>
</body>
</html>



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: MorningZ
Date Posted: 29 August 2003 at 8:43am
btw, not needed in the above:
<%@ Import Namespace="System.Collections"%>


-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Diep-Vriezer
Date Posted: 29 August 2003 at 11:27am

Wow, Thanks!



-------------
Gone..


Posted By: Diep-Vriezer
Date Posted: 29 August 2003 at 12:39pm

It works, thx alot (I edited a little bit, with loop's in it)

Do While aLocalFiles.Length > 0

PicsRepeater.DataSource = aLocalFiles

PicsRepeater.DataBind()

Loop



-------------
Gone..


Posted By: Diep-Vriezer
Date Posted: 29 August 2003 at 12:48pm

 ... Now I recieve the following error:

No default member found for type 'FileInfo'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.MissingMemberException: No default member found for type 'FileInfo'.

Source Error:

Line 131:												<ItemTemplate>
Line 132:													<tr>
Line 133:														<td width="100%" valign="top"><a href="Pics/Images/<%# Container.DataItem("aLocalFiles") %>"><img src="Pics/Thumbs/<%# Container.DataItem("aLocalFiles") %>"></a></td>
Line 134:													</tr>
Line 135:												</ItemTemplate>

Source File: c:\inetpub\wwwroot\sss\Pics\DisplayPics.aspx    Line: 133

Stack Trace:

[MissingMemberException: No default member found for type 'FileInfo'.]
   Microsoft.VisualBasic.CompilerServices.LateBinding.LateIndexGet(Object o, Object[] args, String[] paramnames) +1367
   ASP.DisplayPics_aspx.__DataBind__control4(Object sender, EventArgs e) in c:\inetpub\wwwroot\sss\Pics\DisplayPics.aspx:133
   System.Web.UI.Control.OnDataBinding(EventArgs e) +66
   System.Web.UI.Control.DataBind() +26
   System.Web.UI.Control.DataBind() +86
   System.Web.UI.WebControls.Repeater.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +127
   System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +475
   System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +49
   System.Web.UI.WebControls.Repeater.DataBind() +23
   sss.DisplayPics.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\Floris den Heijer\VSWebCache\192.168.1.35\sss\Pics\DisplayPics.aspx.vb:48
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Page.ProcessRequestMain() +731

With the code-behind file:

Dim sLocalDir, ThisFileName As String

sLocalDir = Server.MapPath("Images/")

If Not Directory.Exists(sLocalDir) Then

Exit Sub

Else

Dim oLocalFile As FileInfo

Dim aLocalFiles As FileInfo() = (New DirectoryInfo(sLocalDir)).GetFiles("*.jpg")

Do While aLocalFiles.Length > 0

PicsRepeater.DataSource = aLocalFiles

PicsRepeater.DataBind()

Loop

End If

And The ASPX file:

 <asp:Repeater id="PicsRepeater" runat="server"><HeaderTemplate>
 <table width="100%" class="regular" cellpadding="5" cellspacing="0" border="1" bordercolor="#B7B7B7">
 <tr>
 <td width="100%" bgcolor="#D0D0D0"><strong>Foto:</strong></td>
 </tr>
 <tr>
 <td width="100%">&nbsp;</td>
 </tr>
 </HeaderTemplate>
 <ItemTemplate>
 <tr>
 <td width="100%" valign="top"><a href="Pics/Images/<%# Container.DataItem("aLocalFiles") %>"><img src="Pics/Thumbs/<%# Container.DataItem("aLocalFiles") %>"></a></td>
 </tr>
 </ItemTemplate>
 <FooterTemplate>
 </table>
 </FooterTemplate>
 </asp:Repeater>

If you want, you can help me, but I think I can handle this one, it's more like to inform you.



-------------
Gone..



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net