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 7519293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:52:43+00:00 2026-05-30T01:52:43+00:00

How can I load all image assets in a particular folder in my XNA

  • 0

How can I load all image assets in a particular folder in my XNA game? The textures are located in the content project like normal, but say instead of copying line after line for each new texture I add, the ability to load them all automatically.

  • 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-30T01:52:44+00:00Added an answer on May 30, 2026 at 1:52 am

    Mainly there are two ways

    1st : Rename your images from 1 to N, so that you can load images in a for loop such as

    List<Texture2D> images = new List<Texture2D>();
    string folderPath = "MyImages/";
    for(int i= 0; i<Count; i++)
    {
       try
       {
            images.Add(Content.Load<Texture2D>(folderPath + i.ToString));
       }
       catch
       {
            break;
       }
    }
    

    the code above works for specific count, you may change for iteration to while(true) incrementing i, the catch blog will break if there is not any images more.

    or use this (put the static class in the namespace of your game-project, not under any sub-namespace folder) it would work. if you do not want to extend your Content than remove “this” from the function)

    public static class MyExtension
    {
            public static List<T> LoadListContent<T>(this ContentManager contentManager, string contentFolder)
            {
                DirectoryInfo dir = new DirectoryInfo(contentManager.RootDirectory + "/" + contentFolder);
                if (!dir.Exists)
                    throw new DirectoryNotFoundException();
                List<T> result = new List<T>();
    
                FileInfo[] files = dir.GetFiles("*.*");
                foreach (FileInfo file in files)
                {
                    result.Add(contentManager.Load<T>(contentFolder + "/" + file.Name.Split('.')[0]));
                }
                return result;
            }
    }
    

    This code has a problem if your real path’s length will be greater than 256, the function will not work. So be careful.

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

Sidebar

Related Questions

I can load COM DLLs that are registered on my machine like this: Type
I don't know what's make wrong, my map can load, but the image on
I want to load a thumbnail representation of an image that is located in
I want to load images from a folder located on my server eg. webimages
Is it possible I can load an image sprite only when needed? For example
Hi there is a google page http://www.google.com/imghp where we can load image and search
Apache Pig can load data from Hadoop sequence files using the PiggyBank SequenceFileLoader :
How can I link the array Buttons to intents so I can load up
I have a web application that can load plugins through reflection. It currently uses
I am wondering how I can load a byte array into a memory URLClassLoader?

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.