Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To Use Embedded Resources?
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB.NET 1.1
Divers
Thread ID:
01122006
Message ID:
01122016
Vues:
25
This message has been marked as the solution to the initial question of the thread.
>I am trying to created an automated create Stored Procedure routine in VB.Net, but the SQL code is a tad long and a pain to manually add into a string. Is there a way I can save the TSQL code as a Text file then embed the file into the VB.Net project/executable and then recall it? In other words, recall the embedded text file and dump it's contents into a string, then use that string in my Create Procedure routine...?
>
>Please help, thanks in advanced.

Ben,
Add your text file to the project and make sure the Build Action = Embedded Resource.
The run the following code (might want to clean it up a little since it is pretty down and dirty):
string myString;
string myResource = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".MyTextFile.txt";
using (Stream myStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(myResource))
{
	using (StreamReader myReader = new StreamReader(myStream))
	{
		myString = myReader.ReadToEnd();
	}
}

MessageBox.Show(myString);
Note: If your file was added to a folder within your project you need to include the folder information in the resource string.

Hope this helps.

Einar
Semper ubi sub ubi.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform