How to use resources and files in C# -
i have program consists of images. want put images in folder , show content of folder dynamically. program should portable. should do? tried following code did not work:
string path = "resources/location.txt"; string path2 = "/iconimagesfordummies/icon"; observablecollection<iconimagesfordummies> icons = new observablecollection<iconimagesfordummies>(); string[] lines = null; if (file.exists(path)) lines = file.readalllines(path, encoding.unicode); if (lines != null) { (int = 0; < lines.length; ++i) { string str = path2 + @"/" + lines[i]; if (file.exists(str)) icons.add(new iconimagesfordummies() { name = str }); } } else throw new exception("the location.txt stores location of icons missing"); if (icons.count == 0) throw new exception("there no icon image"); location.txt contains name of images. problem program not find location.txt. have inserted location.txt in resources. have mention used approach. made new folder , instead of string path = "resources/location.txt";, used folder name did not work too. should do?
if file not copied output folder of project, try setting build action property content , make sure copy output folder property of file set either copy always or copy if newer - depending on requirements of project.
setting build action resource in wpf project compiles file in assembly or executable. why such file not found in output folder.
from msdn:
resource files: data files compiled either executable or library wpf assembly.
Comments
Post a Comment