Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
Is there a way to control the number of the items that the code get from the folder?
Something like this;
<img src="/media/@Model.Content.GetPropertyValue("placeID")/@Path.GetFileName(item) [6 Items Max] " />
Many thanks
Hi Rayyan
This code, that you provided, doesn't return files from the folder.
This is what you need:
string[] files = Directory.GetFiles(folderPath).Take(6).ToArray();
Thanks,
Alex
Thank you Alex,
I just realise that I didn't ask the right question, what i'm looking for is to limit the number of the thumbnails only and keep the foreach as it is.
Is that possible?
<img src="/media/@Model.Content.GetPropertyValue("placeID")/@Path.GetFileName(item) **[take(6)]** " />
@{ string folderPath = Server.MapPath("/media"); string[] files = Directory.GetFiles(folderPath + "/" + Model.Content.GetPropertyValue("placeName")); } @foreach (string item in files){ <li id="firstImage" class="col-xs-6 col-sm-4 col-md-3" data-src="/media/@Model.Content.GetPropertyValue("placeName")/@Path.GetFileName(item)" data-sub-html=""> <a href=""> <img src="/media/@Model.Content.GetPropertyValue("placeName")/@Path.GetFileName(item)"/> </a> </li> }
Rayyan, use this code:
@{ string folderPath = Server.MapPath("/media"); string[] files = Directory.GetFiles(folderPath + "/" + Model.Content.GetPropertyValue("placeName")).Take(6).ToArray(); } @foreach (string item in files){ <li id="firstImage" class="col-xs-6 col-sm-4 col-md-3" data-src="/media/@Model.Content.GetPropertyValue("placeName")/@Path.GetFileName(item)" data-sub-html=""> <a href=""> <img src="/media/@Model.Content.GetPropertyValue("placeName")/@Path.GetFileName(item)"/> </a> </li> }
This code limits the foreach to display 6 items, and what I want is to keep the foreach as it is and limiting the img tag only.
Thanks
How many img tags do you have now?
6 img tags
You will have the same number of img tags on your page as images.
You;re right, but i want to let the foreach displays all the
<li data-src="/media/806.png" data-sub-html=""> <a href=""> <img class="img-responsive" src="/media/806.png"/> </a> </li> <li data-src="/media/853.png" data-sub-html=""> <a href=""> <img class="img-responsive" src="/media/853.png"/> </a> </li> <li data-src="/media/089.png" data-sub-html=""> <a href=""> </a> </li> <li data-src="/media/931.png" data-sub-html=""> <a href=""> </a> </li> <li data-src="/media/061.png" data-sub-html=""> <a href=""> </a> </li> <li data-src="/media/735.png" data-sub-html=""> <a href=""> </a> </li> <li data-src="/media/637.png" data-sub-html=""> <a href=""> </a> </li>
As you can see, only the first 2 img tag (for example) are displayed.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Path.GetFileName(item) - Control the number of items
Hi,
Is there a way to control the number of the items that the code get from the folder?
Something like this;
Many thanks
Hi Rayyan
This code, that you provided, doesn't return files from the folder.
This is what you need:
Thanks,
Alex
Thank you Alex,
I just realise that I didn't ask the right question, what i'm looking for is to limit the number of the thumbnails only and keep the foreach as it is.
Is that possible?
Rayyan, use this code:
This code limits the foreach to display 6 items, and what I want is to keep the foreach as it is and limiting the img tag only.
Thanks
How many img tags do you have now?
6 img tags
You will have the same number of img tags on your page as images.
You;re right, but i want to let the foreach displays all the
and limit the img tag. And the source should looks like this;As you can see, only the first 2 img tag (for example) are displayed.
is working on a reply...