How to read embedded resource text file

前端 未结 22 2839
悲&欢浪女
悲&欢浪女 2020-11-21 06:03

How do I read an embedded resource (text file) using StreamReader and return it as a string? My current script uses a Windows form and textbox that allows the

22条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-21 06:35

    In Visual Studio you can directly embed access to a file resource via the Resources tab of the Project properties ("Analytics" in this example). visual studio screen shot - Resources tab

    The resulting file can then be accessed as a byte array by

    byte[] jsonSecrets = GoogleAnalyticsExtractor.Properties.Resources.client_secrets_reporter;
    

    Should you need it as a stream, then ( from https://stackoverflow.com/a/4736185/432976 )

    Stream stream = new MemoryStream(jsonSecrets)
    

提交回复
热议问题