Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9127895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:23:26+00:00 2026-06-17T07:23:26+00:00

I am trying to create a small web app, that when I type in

  • 0

I am trying to create a small web app, that when I type in a game name, it will search through a folder with a whole lot of icons to find one similar to the typed in game.

I then want to show a repeater with the name of the icon, as well as the icon next to it.

So far I have successfully displayed the name with this code:

IEnumerable<string> getfiles =
            from f in
                Directory.EnumerateFiles(Server.MapPath("~/_resources/game_icon"), "*.*", SearchOption.AllDirectories)
            where Path.GetFileName(f).ToLower().Contains(txtGameName.Text.ToLower())
            select Path.GetFileNameWithoutExtension(f);

        List<AllFiles> all = getfiles.Select(file => new AllFiles
            {
                FileName = file, 
                SubdirectoryName = "",
                FileNameWithExtension = ""
            }).ToList();

        rptGameMatches.DataSource = all;
        rptGameMatches.DataBind();

But havent had much luck in displaying the icon, which would be in ImageLocation.

Ive tried playing with:

foreach (string file in Directory.EnumerateFiles(Server.MapPath("~/_resources/game_icon"), "*.*", SearchOption.AllDirectories).Count() )
        {
            if(file.)
        }

and

for (int i = 0; i < Directory.EnumerateFiles(Server.MapPath("~/_resources/game_icon"), "*.*", SearchOption.AllDirectories).Count(); i++)
        {

        }

With no success.

I know there is a simplistic way to do this, but I cant quite seem to get it right. Could someone please show me where I’m going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:23:27+00:00Added an answer on June 17, 2026 at 7:23 am

    Here’s an example of what you could do (for compactness reasons I have placed the code behind and the markup inside a single WebForm but of course you could have the code behind in a separate file):

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.IO" %>
    
    <script type="text/c#" runat="server">
        protected void BtnSearchClick(object sender, EventArgs e)
        {
            var images =
                from image in Directory.EnumerateFiles(Server.MapPath(folder), "*.*", SearchOption.AllDirectories)
                let relativeLocation = image.Replace(root, string.Empty).Replace("\\", "/")
                let url = ResolveUrl("~/" + relativeLocation)
                where image.ToLower().Contains(txtGameName.Text.ToLower())
                select new 
                {
                    Url = url
                };
    
            results.DataSource = images;
            results.DataBind();
        }
    </script>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:TextBox ID="txtGameName" runat="server" />
            <asp:LinkButton ID="btnSearch" runat="server" OnClick="BtnSearchClick" Text="Search" />
            <asp:Repeater ID="results" runat="server">
                <ItemTemplate>
                    <asp:Image runat="server" ImageUrl='<%# Eval("Url") %>' />
                </ItemTemplate>
            </asp:Repeater>
        </div>
        </form>
    </body>
    </html>
    

    Alright, so we have a web page containing a text field, a button and a repeater. When the button is clicked we are searching for all images in the specified folder whose name contains the text entered into the text field:

    var images =
        from image in Directory.EnumerateFiles(Server.MapPath(folder), "*.*", SearchOption.AllDirectories)
        let relativeLocation = image.Replace(root, string.Empty).Replace("\\", "/")
        let url = ResolveUrl("~/" + relativeLocation)
        where image.ToLower().Contains(txtGameName.Text.ToLower())
        select new 
        {
            Url = url
        };
    

    There are a few steps here:

    let filename = Path.GetFileName(image)
    

    at this stage we are getting the physical location to the file. It will look like this:

    c:\inetpub\wwwroot\_resources\game_icon\image1.png
    

    Then we strip the application root and replace the slashes:

    let relativeLocation = filename.Replace(root, string.Empty).Replace("\\", "/")
    

    so relativeLocation becomes:

    _resources/game_icon/image1.png
    

    and the last step is:

    let url = ResolveUrl("~/" + relativeLocation)
    

    which will turn that into:

    /_resources/game_icon/image1.png
    

    So at the end of the day the images collection might look like this (assuming the user searched for image in the text field):

    [
        { Url: "/_resources/game_icon/image1.png" },
        { Url: "/_resources/game_icon/subfolder1/image2.png" },
        { Url: "/_resources/game_icon/subfolder2/image1.png" },
        ...
    ]
    

    It is this collection that is bound to the repeater. Inside the repeater we have defined an Image whose ImageUrl property will be data bound to the Url property of the anonymous object we constructed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a small web app that will allow users to
I'm trying to create a small web app that is used to remove items
I'm trying to create a small Web App to categorize certain type of YouTube
I am trying to create a small web app for my android device, I
I am trying create a small web application that allows a user to login
I'm trying to create a small web service to convert PDF files to a
I am trying to create a small assembly program to create a folder. I
I have a small program that I'm trying to create to get ip addresses
I'm trying to create a small application within CRM in the ISV folder. I
I am trying to figure out how to create a small web page onload()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.