问题
I'd like to list files in a given folder (which is in another project) in Silverlight. Actually, they are images.
Project A : "/Images/a.png" "/Images/b.png" Project B : I want to list the files in "Project A/Images/"
I haven't found a way to do it, can you help me ?
Thanks
回答1:
You can use reflection to perform this at runtime. If you set the build action of your images to "embedded resource", you can enumerate them at runtime.
// locate the assembly
Assembly thisAssembly = Assembly.GetExecutingAssembly();
// list all the resources
string[] resNames = thisAssembly.GetManifestResourceNames();
foreach (string resName in resNames)
{
if (resName.ToLower().EndsWith(".png"))
{
// do something!
}
}
Note, if the images are in a different project / assembly, you may have to navigate to this assembly before enumerating the resources.
来源:https://stackoverflow.com/questions/4711590/list-files-in-a-silverlight-project