Reading an embedded text file

后端 未结 3 2412
忘了有多久
忘了有多久 2021-02-20 13:07

I have created a full project which works perfectly. My problem concerns the setup project. When I use it on another computer, the text file cannot be found even if they are ins

3条回答
  •  时光取名叫无心
    2021-02-20 13:50

    create this function to read whatever embedded resource text file you have :

    public string GetFromResources(string resourceName)
    {
        Assembly assem = this.GetType().Assembly;
    
        using (Stream stream = assem.GetManifestResourceStream(resourceName))
        {
            using (var reader = new StreamReader(stream))
            {
                return reader.ReadToEnd();
            }
    
        }
    }
    

提交回复
热议问题