Hello guys,

Would anybody be so kind to tell me how to read a .txt I embedded in a C#
class library?

Thanks a lot,

Re: Read a .txt resource embedded in a Class Library by Carlos

Carlos
Thu Jun 07 15:53:22 CDT 2007

So... I ended up with this code (now I'm looking how to convert a
StreamReader to a String using C#
But actually I don't remember it was so hard to obtain a string from a .txt
file embedded in a VB project. Am I wrong?

Assembly _assembly;
_assembly = Assembly.GetExecutingAssembly();
StreamReader _textStreamReader;
_textStreamReader = new
StreamReader(_assembly.GetManifestResourceStream("MyClassLibrary.MyFolder.MyFile.txt"));


"Carlos Sosa Albert" <betun (at) hotmail> wrote in message
news:ezgM8IUqHHA.1052@TK2MSFTNGP03.phx.gbl...
> Hello guys,
>
> Would anybody be so kind to tell me how to read a .txt I embedded in a C#
> class library?
>
> Thanks a lot,


Re: Read a .txt resource embedded in a Class Library by Jon

Jon
Thu Jun 07 16:39:21 CDT 2007

<"Carlos Sosa Albert" <betun (at) hotmail>> wrote:
> So... I ended up with this code (now I'm looking how to convert a
> StreamReader to a String using C#
> But actually I don't remember it was so hard to obtain a string from a .txt
> file embedded in a VB project. Am I wrong?
>
> Assembly _assembly;
> _assembly = Assembly.GetExecutingAssembly();
> StreamReader _textStreamReader;
> _textStreamReader = new
> StreamReader(_assembly.GetManifestResourceStream("MyClassLibrary.MyFolder.MyFile.txt"));

By the time you've put the assignments in the same statements as the
declarations, that's two (admittedly long) lines of code. If that's
*really* too much, you can put it into a helper method really easily.

As for converting a StreamReader to a String - StreamReader.ReadToEnd
is your friend :)

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Re: Read a .txt resource embedded in a Class Library by Carlos

Carlos
Fri Jun 08 08:47:07 CDT 2007

Actually, I was sure I didn't have to specify "by hand" MyFile.txt but the
helper was doing so.
But maybe I wrote some code then to do that.

"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.20d28b64f0a746931d8@msnews.microsoft.com...
> <"Carlos Sosa Albert" <betun (at) hotmail>> wrote:
>> So... I ended up with this code (now I'm looking how to convert a
>> StreamReader to a String using C#
>> But actually I don't remember it was so hard to obtain a string from a
>> .txt
>> file embedded in a VB project. Am I wrong?
>>
>> Assembly _assembly;
>> _assembly = Assembly.GetExecutingAssembly();
>> StreamReader _textStreamReader;
>> _textStreamReader = new
>> StreamReader(_assembly.GetManifestResourceStream("MyClassLibrary.MyFolder.MyFile.txt"));
>
> By the time you've put the assignments in the same statements as the
> declarations, that's two (admittedly long) lines of code. If that's
> *really* too much, you can put it into a helper method really easily.
>
> As for converting a StreamReader to a String - StreamReader.ReadToEnd
> is your friend :)
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too


Re: Read a .txt resource embedded in a Class Library by Carlos

Carlos
Fri Jun 08 08:59:06 CDT 2007

Oh, I remember... I used this... Wonder if it has something wrong...?
String xx = MyLibrary.Properties.MyResource;

Thanks Jon!

"Jon Skeet [C# MVP]" <skeet@pobox.com> wrote in message
news:MPG.20d28b64f0a746931d8@msnews.microsoft.com...
> <"Carlos Sosa Albert" <betun (at) hotmail>> wrote:
>> So... I ended up with this code (now I'm looking how to convert a
>> StreamReader to a String using C#
>> But actually I don't remember it was so hard to obtain a string from a
>> .txt
>> file embedded in a VB project. Am I wrong?
>>
>> Assembly _assembly;
>> _assembly = Assembly.GetExecutingAssembly();
>> StreamReader _textStreamReader;
>> _textStreamReader = new
>> StreamReader(_assembly.GetManifestResourceStream("MyClassLibrary.MyFolder.MyFile.txt"));
>
> By the time you've put the assignments in the same statements as the
> declarations, that's two (admittedly long) lines of code. If that's
> *really* too much, you can put it into a helper method really easily.
>
> As for converting a StreamReader to a String - StreamReader.ReadToEnd
> is your friend :)
>
> --
> Jon Skeet - <skeet@pobox.com>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too