请问如何在c#中使用内嵌的资源文件,我的资源文件是一个txt文件

解决方案 »

  1.   

    string _Text =Properties.Resources.资源文件名;
      

  2.   

    我手动添加了一个txt文件作为资源文件,但是不知道如何使用它
      

  3.   

    我要读取这个文件,请问怎么做?Properties.Resources.knee4012, 我得到的是byte[]
      

  4.   

    那你的文件名不是txt ..你可以string _Text =System.Text.Encoding.Default.GetString(你取到的byte[]);
      

  5.   

    怎么得到的byte array 里面的值都是0啊,得到的string 是空,这是为什么
      

  6.   

    我的资源文件是hex文件,开始我说错了,
      

  7.   

    大家帮忙啊, 我加载的是hex 文件
      

  8.   

    public static string GetEmbeddedResourceContent(string NameSpance, string ResourceName)
            {
                string content = "";
                try
                {
                    Stream Stream = Assembly.Load(NameSpance).GetManifestResourceStream(ResourceName);
                    Stream.Position = 0;
                    StreamReader sr = new StreamReader(Stream);
                    content = sr.ReadToEnd();
                }
                catch (Exception)
                {
                }
                finally { }
                return content;
            }
    NameSpance就是命名空间,ResourceName就是命名空间加资源文件名