list files in a silverlight project

2019-09-05 05:36发布

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条回答
仙女界的扛把子
2楼-- · 2019-09-05 06:36

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.

查看更多
登录 后发表回答