2

Possible Duplicate:
How to read embedded resource text file

I try to create a simple application which reads out from a "resource" file, which I've already add into my solution. I've tried this, but this doesn't work:

static void Main(string[] args)
{
    StreamResourceInfo streamResourceInfo = Application.GetContentStream(new Uri("pack://application:,,,/myfile.txt", UriKind.Absolute));
    StreamReader sr = new StreamReader(streamResourceInfo.Stream);
    var content = sr.ReadToEnd();
    Console.WriteLine(content);
}

It says: "Invalid URI: Invalid port specified."

How can I solve this?

Community
  • 1
  • 1
Zsolt
  • 3,263
  • 3
  • 33
  • 48
  • 6
    Did you check [how to read embedded ressource file](http://stackoverflow.com/questions/3314140/how-to-read-embedded-resource-text-file) ? I think this should help you out! – Pilgerstorfer Franz Oct 12 '12 at 10:18

1 Answers1

4

My final solution:

class Program
{
    static void Main(string[] args)
    {
        Stream stream = typeof(Program).Assembly.GetManifestResourceStream("TheNameOfMyProject.TheNameOfSubFolder.file.txt");
        StreamReader sr = new StreamReader(stream);
        var content = sr.ReadToEnd();
        Console.WriteLine(content);
        Console.ReadLine();
    }
}
Zsolt
  • 3,263
  • 3
  • 33
  • 48