HI,

I am quite new in this field.I am developing one C# web application .can you help me with following stuff.

I want to Display images from a folder which contains nearly 1000 images.

That image files in folder(means image itself) has names like 15_1,15_2,15_5,15_40,18_1,18_3... where first field is id which i have to compare with plantid field and if match found then show all the images i.e. say plantid=15 then if plantid=imgeid is true then show the images with names 15_1,15_2,15_5,15_40

1.how i will get that 15 for comparison?
2.which control is used to show images?

Please help me !

Thanks in advance for spending time here for me.thanks again!!!

Dani AI

Generated

Asking how to show images named like 15_1, 15_2 for a given plant id has already seen two good approaches in this thread: suggested extracting the prefix and showed a split-and-create-Image example. Both work, but a clearer and more robust pattern is to treat the images folder as a data source and select files that start with the plant id plus an underscore. Validate the plant id first (numeric or strict string), then build a file search rather than parsing every filename manually.

A concise server-side pattern is to enumerate files that match the pattern plantid_* and turn file names into relative URLs for binding. For example:

string plantId = /* validated id */;
var files = Directory.EnumerateFiles(Server.MapPath("~/Images"), plantId + "_*.*");
foreach (var file in files) {
    string name = Path.GetFileName(file);
    // add "~/Images/" + name to a data source for binding
}

For display, bind the resulting URL list to a Repeater/DataList/ListView and render an <img> or <asp:Image> for each item. For slideshow behavior prefer a client-side slider (bind all thumbs and let JS handle transitions) or keep a single asp:Image and change its ImageUrl on next/prev while storing the file list in ViewState/Session.

Practical caveats and tips: generate and serve thumbnails (do not send full-size images for galleries), cache the file list (MemoryCache or Application) instead of hitting the disk every request, use EnumerateFiles (streams results) and Path.GetExtension to filter valid image types, and sanitize plantId to avoid accidental path matches. Also ensure the IIS account has read permission on the images folder and set appropriate client-side caching headers to reduce load.

Recommended Answers

All 5 Replies

Can u tel me what is plantid, How to want to show the image with scenario

First of all thanks for ur replay!!!!!

that plantid is some datavalue like that 15
and i have to match that plantid means 15 with image names like15_1,15_5,16_1,16_4....
if match found that is in our case image names 15_1,15_5,
I have to show this two images on web page.
it may be in slide set or with next prev button.

Even i am not sure which control to be use?

u can get 15 for compare with plantid by th following steps..

first take the substring of image name (int i=imagename.indexOf(_);
string substring=imagename.substring(0,i);)
and
convert it into int.parse(substring)

u can get 15 for compare with plantid by th following steps..

first take the substring of image name (int i=imagename.indexOf(_);
string substring=imagename.substring(0,i);)
and
convert it into int.parse(substring)

thanks fro ur valuable replay !let me check this then i will tell u what happens

Ramsham,

Check this code

protected void Page_Load(object sender, EventArgs e)
    {
        string plantid  = "15";
        string strimagelist = "15_1,15_2,15_5";
        string[] strimagecomma = strimagelist.Split(',');
        string[] strimageunderscore = null;
        foreach (string strcompare in strimagecomma)
        {
            strimageunderscore = strcompare.Split('_');
            for (int i = 0; i < strimageunderscore.Length; i++)
            {
                if (plantid == strimageunderscore[i])
                {
                    Image img = new Image();
                    img.ID = "img" + strimageunderscore[i] + "_" + strimageunderscore[i + 1];
                    img.ImageUrl = "~/Images/" + strimageunderscore[i] + "_" + strimageunderscore[i + 1] + ".jpg";
                    pnlView.Controls.Add(img);
                    break;
                }
            }
            strimageunderscore = null;
        }

    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.