Read from a JSON file inside a project

前端 未结 3 1989
悲&欢浪女
悲&欢浪女 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:48
    using (StreamReader r = new StreamReader(Application.StartupPath + @"/Resources/Settings.json"))
    
    0 讨论(0)
  • 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))
    
    0 讨论(0)
  • 2020-12-31 13:55
    Directory.GetCurrentDirectory();
    
    0 讨论(0)
提交回复
热议问题