I'm using Visual Studio 2010 with a C# WPF app and I've added some images into a subfolder called assets. Is there any way I can loop through all the images that i've added to the folder using pack URIs or something similar?
Asked
Active
Viewed 1,584 times
1
-
You have asked 22 questions only 11 of them you have accepted an answer. – Security Hound May 03 '11 at 12:54
-
Thats what that means! I thought it meant percentage of people who accepted my questions or something of the sort. Thanks. – Jack May 08 '11 at 23:05
1 Answers
1
The following method gets all the file names in a resource-folder:
public static string[] GetResourcesUnder(string folder)
{
folder = folder.ToLower() + "/";
var assembly = Assembly.GetCallingAssembly();
var resourcesName = assembly.GetName().Name + ".g.resources";
var stream = assembly.GetManifestResourceStream(resourcesName);
var resourceReader = new ResourceReader(stream);
var resources =
from p in resourceReader.OfType<DictionaryEntry>()
let theme = (string)p.Key
where theme.StartsWith(folder)
select theme.Substring(folder.Length);
return resources.ToArray();
}
Just need to put the head back on when you use them:
var files = GetResourcesUnder("Images");
foreach (var file in files)
{
string uriPath = "pack://application:,,,/Images/" + file;
//...
}
I did not write this method, it's from another question here on SO, i'll try to find it...
Edit: It's from here.