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

  • SEARCH
  • Home
  • 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 467283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:33:54+00:00 2026-05-12T23:33:54+00:00

I’m making a C# image gallery for a website (I know there’s many free

  • 0

I’m making a C# image gallery for a website (I know there’s many free ones out there, but I want the experience). I’m grabbing files from a directory on the website by storing them in a array.

protected void Page_Load(object sender, EventArgs e)
    {
        string[] files = null; 

        files = Directory.GetFiles(Server.MapPath(@"Pictures"),"*.jpg");

I then am creating an array of Imagebuttons (which I will use as thumb-nails) and I’m dynamically adding them into a panel on the web form. However, the image buttons are added on the form correctly, but the pictures show the little square/circle/triangle symbol and fail to load the actual image.

ImageButton[] arrIbs = new ImageButton[files.Length – 1];

for (int i = 0; i < files.Length-1; i++)
{
    arrIbs[i] = new ImageButton();
    arrIbs[i].ID = "imgbtn" + Convert.ToString(i);
    arrIbs[i].ImageUrl = Convert.ToString(files[i]);
    Response.Write(Convert.ToString(files[i]) + "**--**");
    arrIbs[i].Width = 160;
    arrIbs[i].Height = 100;
    arrIbs[i].BorderStyle = BorderStyle.Inset;
    //arrIbs[i].BorderStyle = 2;
    arrIbs[i].AlternateText = System.IO.Path.GetFileName(Convert.ToString(files[i]));
    arrIbs[i].PostBackUrl = "default.aspx?Img=" + Convert.ToString(files[i]);

    pnlThumbs.Controls.Add(arrIbs[i]);

}

}

This may or may not be related to the issue (if not related, it is a sub-question). When setting the Server.MapPath() to @”~/Gallery/Pictures” (which is where the directory is in relevance to the site root) I get an error. It states that “C:/…/…/…/… could not be found” The web-site only builds if I set the directory as “Pictures”, which is where the pictures are, and “Pictures” is in the same folder as “Default.aspx” which the above code is at. I never have much luck with the ~ (tilda) character. Is this a file-structure issue, or a IIS issue?

  • 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-05-12T23:33:55+00:00Added an answer on May 12, 2026 at 11:33 pm

    The problem with this is that you’re setting a path on the server as the image button source. The browser will try to load these images from the client’s machine, hence they cannot load. You will also need to make sure that the ASPNET user on the server has permissions to that folder.

    What you need to do is to serve the jpeg’s streams as the source for the image buttons.

    You could have an aspx page which takes in the path in a query string parameter and loads the file and serves it.

    Eg, have a page called GetImage.aspx as such:

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.IO" %>
    
    <script runat="server" language="c#">
        public void Page_Load()
        {
            try
            {
                Response.Clear();
                Response.ContentType = "image/jpeg";
                string filename = Page.Request.QueryString["file"];
                using (FileStream stream = new FileStream(filename, FileMode.Open))
                {
                    int streamLength = (int)stream.Length;
                    byte[] buffer = new byte[streamLength];
                    stream.Read(buffer, 0, streamLength);
                    Response.BinaryWrite(buffer);
                }
            }
            finally
            {
                Response.End();
            }
        }
    </script>
    

    and now when you create your ImageButtons, this should be your ImageUrl:

    arrIbs[i].ImageUrl = String.Format("GetImage.aspx?file={0}", HttpUtility.UrlEncode(files[i]));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm making a simple page using Google Maps API 3. My first. One marker
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.