Read from a JSON file inside a project

前端 未结 3 1988
悲&欢浪女
悲&欢浪女 2020-12-31 13:01

I have a directory named Resources in my WPF project and I have a Settings.json inside that directory. I want to read content from that fil

3条回答
  •  隐瞒了意图╮
    2020-12-31 13:49

    Since you've got your Build Action set to Embedded Resource, you probably want to use the Assembly.GetManifestResourceStream method.

    For example:

    using (Stream stream = assembly.GetManifestResourceStream("MyCompany.Namespace.Settings.json"))
    using (StreamReader reader = new StreamReader(stream))
    

提交回复
热议问题