How to read embedded resource text file

前端 未结 22 2330
悲&欢浪女
悲&欢浪女 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:37

    You can also use this simplified version of @dtb's answer:

    public string GetEmbeddedResource(string ns, string res)
    {
        using (var reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(string.Format("{0}.{1}", ns, res))))
        {
            return reader.ReadToEnd();
        }
    }
    

提交回复
热议问题