473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help ! how to read a resource into a string

Hello

What I want :
Embed a HTML file into my C# program and then
read the complete HTML resource into a string.

Can anybody tell me how to do that or better where I find a working sample ?

What I already did :
I added the HTML file in Visual Studio .NET to the solution via
Add --> Add Existing Item.

Under Properties I've set it to
Build Action = Embedded resource

When I look into the resulting EXE with an HEX editor I can see
that the HTML file has been compiled into the EXE file !

Nice !
But how do I read it into a string ?
I searched for hours without success !

Elmü

Nov 16 '05 #1
2 1805
Elmue <no*****@gmx.com> wrote:
What I want :
Embed a HTML file into my C# program and then
read the complete HTML resource into a string.

Can anybody tell me how to do that or better where I find a working sample ?

What I already did :
I added the HTML file in Visual Studio .NET to the solution via
Add --> Add Existing Item.

Under Properties I've set it to
Build Action = Embedded resource

When I look into the resulting EXE with an HEX editor I can see
that the HTML file has been compiled into the EXE file !

Nice !
But how do I read it into a string ?
I searched for hours without success !


Find out your current assembly with Assembly.GetExecutingAssembly().
Call Assembly.GetManifestResourceStream() to get a stream.
Wrap it in a StreamReader, and call ReadToEnd().

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Hello

Thanks for your answer !
I would never have found that.

But an important information was missing :
What exactly to pass to GetManifestResourceStream(string) ?

I found it now and here is the code if someone else needs it :

// how to read an embedded resource with the filename "Template.htm" into a string:
using System.Reflections;using System.IO;
Assembly Assm = Assembly.GetExecutingAssembly();Stream MyStream = Assm.GetManifestResourceStream("MyProject.Resource s.Template.htm");StreamReader StrmRead = new StreamReader(MyStream);string HtmTempl = StrmRead.ReadToEnd();

Elmü
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
3
by: Kendall Gifford | last post by:
Greetings. While trying to get a simple app working, I've been forced to delve into embedded and/or linked resources a bit. I read all the reference for the System.Resources namespace as well as...
0
by: Terry | last post by:
I want to have seperate satellite assembly dlls which contain string resources for the different languages. Maybe what I'm trying to do is nonstandard, but I'd *like* have the actual string...
4
by: Leonardo Hyppolito | last post by:
Hello, I am trying to write a multithread program that simulates producers and consumers. My program can have many producers and many consumers (each in a separate thread). It has a storage...
15
by: Yogi_Bear_79 | last post by:
Visual Studio .NET started complaing when the array was around 4000. I found that if I pasted the array in via notepad then opened Visual Studio it would work. Now my array is over 26,000 and...
4
by: Jacob.Bruxer | last post by:
Hi, I'm pretty new to Visual Basic and was wondering if anyone could give some general advise on how to conserve memory when running a Visual Basic program that I've created. I keep getting a...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
3
by: Robert Dufour | last post by:
I am trying to localize a very simple web site (english and french) I have a master page and one content page for now. On the master page I have placed a Localize control On the content page I...
8
by: =?Utf-8?B?WVhR?= | last post by:
I want to do the multi-language program, save the language text in XML file, but how to read the specified node value? the xml is below, for example, i want to get the value(AAA content) that named...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.