Reputation: 4097
Let me explain:
this is path to this folder: > www.my_site.com/images
And images are created by user_id
, and for example, images of user_id = 27
are,
27_1.jpg
, 27_2.jpg
, 27_3.jpg
!
How to list and print images which start with 27_%.jpg
?
I hope You have understood me!
PS. I am totally beginmer in ASP.NET (VB) and please give me detailed information
Here starts my loop
while dbread.Read()
'and then id user_id
dbread('user_id')
NEXT???
I nedd to create XML, till now I created like this:
act.WriteLine("") act.WriteLine("http://www.my_site.com/images/"&dbread("user_id")&"_1.jpg") act.WriteLine("")
But this is not answer because I need to create this nodes how many images of this user exist?
In database doesn't exist list of this images so that is reason why I must count them in folder. (this is not my site exacly, but I need to create XMl on this site)
Do you understand me?
Upvotes: 1
Views: 1298
Reputation: 63136
The appropriate method would be to do the following
Basically the GetFiles method accepts a path, and a "filter" parameter which allows you to do a wildcard search!
EDIT: The GetFiles operation returns a listing of strings that represent the full file name, you can then manipulate those values using the System.IO.Path.GetFileName() method to get the actual file name.
You can use the XmlDocument class if you want to actually build the document, or you could do it with a simple loop and a string builder. Something like the following.
StringBuilder oBuilder = new StringBuilder();
oBuilder.Append("<root>");
string[] ofiles = Directory.GetFiles("YourPath", "yourMask");
foreach(string currentString in oFiles)
{
oBuilder.AppendLine("<file>http://yourpath/" + Path.GetFileName(currentString) + "</file>");
}
oBuilder.Append("</root");
Upvotes: 1
Reputation: 37222
The best way is to just loop through all the files in the directory.
While dbRead.Read
dim sUserId as String= dbread('user_id')
For Each sFile As String In IO.Directory.GetFiles("C:\")
if sFile.StartsWith (sUserId) Then
'Do something.
End If
Next
Loop
However, to actually show the images, you're best bet could be to create a datatable of these images, and then use a datalist or repeater control to display them.
Dim dtImages as new DataTable
dtImages.Columns.Add("Filename")
If dbRead.Read
dim sUserId as String= dbread('user_id')
For Each sFile As String In IO.Directory.GetFiles("C:\")
if sFile.StartsWith (sUserId) Then
Dim drImage as DataRow = dtImages.NewRow
drImage("Filename") = sFile
dtImages.Rows.add(drImage)
End If
Next
End If
dlImages.DataSource = dtImages
dlImages.DataBind
Then, on your ASPX page, you would have a datalist control called dlImages defined like:
<asp:datalist id="dlImages" RepeatDirection="Horizontal" runat="server" RepeatLayout="Flow" Height="100%">
<ItemTemplate>
<asp:Image ID="Image1" Runat=server ImageUrl='<%# Server.MapPath("photos") & Container.DataItem("FileName") %>'>
</asp:Image>
</ItemTemplate>
</asp:datalist>
Upvotes: 1