Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version
Go to top

Create String Variables from Embedded Resources Files

, 15 Jun 2004
Use embedded text files as the source for populating large string variables.
embeddedresoucetextexample.zip
EmbeddedResouceTextExample
App.ico
bin
Debug
EmbeddedResouceTextExample.csproj.user
Folder
obj
Debug
temp
TempPE
embeddedresourcereader.zip
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace McKechney.EmbeddedResouceTextExample
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class ExampleForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.RichTextBox rtbResults;
		private System.Windows.Forms.Button btnGetQuote;
		private System.Windows.Forms.Button btnGetSQL;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ExampleForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.rtbResults = new System.Windows.Forms.RichTextBox();
			this.btnGetQuote = new System.Windows.Forms.Button();
			this.btnGetSQL = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// rtbResults
			// 
			this.rtbResults.Location = new System.Drawing.Point(24, 72);
			this.rtbResults.Name = "rtbResults";
			this.rtbResults.Size = new System.Drawing.Size(440, 312);
			this.rtbResults.TabIndex = 0;
			this.rtbResults.Text = "";
			// 
			// btnGetQuote
			// 
			this.btnGetQuote.Location = new System.Drawing.Point(24, 24);
			this.btnGetQuote.Name = "btnGetQuote";
			this.btnGetQuote.TabIndex = 1;
			this.btnGetQuote.Text = "Get Quote";
			this.btnGetQuote.Click += new System.EventHandler(this.btnGetQuote_Click);
			// 
			// btnGetSQL
			// 
			this.btnGetSQL.Location = new System.Drawing.Point(128, 24);
			this.btnGetSQL.Name = "btnGetSQL";
			this.btnGetSQL.TabIndex = 2;
			this.btnGetSQL.Text = "Get SQL";
			this.btnGetSQL.Click += new System.EventHandler(this.btnGetSQL_Click);
			// 
			// ExampleForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(504, 406);
			this.Controls.Add(this.btnGetSQL);
			this.Controls.Add(this.btnGetQuote);
			this.Controls.Add(this.rtbResults);
			this.Name = "ExampleForm";
			this.Text = "Embedded Resource Text Eample";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new ExampleForm());
		}

		private void btnGetQuote_Click(object sender, System.EventArgs e)
		{
			string quote = new EmbeddedResourceTextReader().GetFromResources("McKechney.EmbeddedResouceTextExample.Folder.Shakespeare.txt");
			this.rtbResults.Text = quote;
		}

		private void btnGetSQL_Click(object sender, System.EventArgs e)
		{
			string sql = new EmbeddedResourceTextReader().GetFromResources("McKechney.EmbeddedResouceTextExample.CreateTable.sql");
			this.rtbResults.Text = sql;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Michael McKechney
Web Developer
United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 16 Jun 2004
Article Copyright 2004 by Michael McKechney
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid