列出Silverlight项目中的文件 [英] list files in a silverlight project
问题描述
我想在Silverlight中列出给定文件夹(位于另一个项目中)中的文件.实际上,它们是图像.
I'd like to list files in a given folder (which is in another project) in Silverlight. Actually, they are images.
项目A:"/Images/a.png""/Images/b.png" 项目B:我想在项目A/图像/"中列出文件
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 ?
谢谢
推荐答案
您可以使用反射在运行时执行此操作.如果将图像的构建操作设置为嵌入式资源",则可以在运行时枚举它们.
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.
这篇关于列出Silverlight项目中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!