Wrox Programmer Forums
|
VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1). ** Please don't post code questions here ** For issues specific to a particular language in .NET, please see the other forum categories.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 3rd, 2004, 05:39 PM
Registered User
 
Join Date: Feb 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Embed text files in DLL

I'd like to embed a text file into a DotNet DLL.

I can add the .txt file to my project, but how do I refer to it programatically?

-BillG_SD
 
Old February 3rd, 2004, 06:42 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Take a look at the following article:

http://Imar.Spaanjaars.Com/QuickDocID.aspx?QUICKDOC=168

This article explains how to embed an image into a Pocket PC Windows forms application, but the principle is the same for all kinds of applications (in fact, anything that can be marked as an assembly) and all kinds of documents you want to embed.

While embedding it is the same, you'll need to retrieve it a bit differently.

First of all, add a using System.IO to your application which you need to access the Stream and StreamReader classes.

Then, in the Load event of the application replace the code that reads the image with this:
Code:
Stream myStream = Assembly.GetExecutingAssembly().
       GetManifestResourceStream("EmbeddedTextFiles.IncludeMe.txt");
StreamReader myReader = new StreamReader(myStream);
MessageBox.Show("File Contains: " + myReader.ReadToEnd());
(This code assumes you added a file called IncludeMe.txt to the root of your project)
The hard part of this code is getting the File into a Stream object (similar to retrieving the image). It's then pretty easy to create a new StreamReader based on this Stream, and then use its ReadToEnd method to read in the entire file.

HtH,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
DLL files nishab345 VB How-To 1 June 17th, 2007 11:37 PM
dll config files - included in the build stuarth General .NET 1 July 20th, 2005 06:42 AM
dll config files - included in the build stuarth VS.NET 2002/2003 0 July 13th, 2005 06:59 AM
Permission denied in acessing dll files sobhamuktha VB Components 6 February 4th, 2005 08:17 AM
dll.files in a executable file KennethMungwira VB.NET 1 December 12th, 2003 05:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.