list files in a silverlight project

谁说我不能喝 提交于 2019-12-12 05:37:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!