开发者

C#: Reference Application Resource File

If 开发者_如何学运维I have a File Default.html in my project

C#: Reference Application Resource File

How can I read it in code? I need the path

One Possible Solution

./Controls/MarkdownEditor/Templates/Default.html works too. Also I set "Copy to output directory" to "Copy if newer"


Normally using this:

   Assembly.GetExecutingAssembly().GetManifestResourceStream(
            "MarkDownEditMVVM.Controls.MarkDownWditor.Templates.Default.Html");

Unless you are using special namespaces.


You need to set the build action for that file to "Embedded Resource" in Visual Studio (right click the file and choose properties).

Then read the file in your code like this:

Assembly asm = Assembly.GetExecutingAssembly();  
Stream stream = asm.GetManifestResourceStream(asm.GetName().Name + ".Default.html");  


Have you had a look at AppDomain.BaseDirectory Property or AppDomainSetup.ApplicationBase Property (System)

and Path.Combine Method (String, String) to get to the directory required?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜