473,508 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I embed a text file in my exe?

I have an application that creates a database from a text file of DDL
(generated by Visio). Currently I have to deploy the text file with my
application and open it using the statement: SQL =
My.Computer.FileSystem.ReadAllText("CreateDB.SQL") .

This works fine, but I would prefer not to have to deploy a separate text
file, and I would like to prevent the users from having access to this file.

Is there some way to easily embed the text file into the compiled
executable? If there is, I will also need to know how to open and read from
an embedded file.

May 9 '06 #1
4 6502
David,

You can add the file to your project, then set its Build ACtion to
'Embedded Resource' through the IDE. You can then access it using a
function like the one below (there may be a cleaner way but this is
what I've used for similar files in the past)

Note: The FileName variable will be "[NameSpace].[FileName]" where
NameSpace is the namespace of your project (if you have one defined) in
the project properties. I just wrote up a console app and I had to use
"ConsoleApplication3.TextFile1" to stream it.

Function GetFileContents(ByVal FileName As String) As String

Dim this As [Assembly]
Dim fileStream As IO.Stream
Dim streamReader As IO.StreamReader
Dim strContents As String
this = System.Reflection.Assembly.GetExecutingAssembly
fileStream = this.GetManifestResourceStream(FileName)
streamReader = New IO.StreamReader(fileStream)
strContents = streamReader.ReadToEnd
streamReader.Close()
Return strContents

End Function

May 10 '06 #2
Please ignore I worked this out myself as follows (to easy with VS2005):

- Open My Project and go to the Resources tab
- Click "Add Resource", then "Add Existing File" and select the DDL file
(in my case CreateDB.SQL)

The file is now an embedded resource and can be accessed as follows:

SQL = My.Resources.CreateDB

Note the file extension is dropped when it is added to the resources.

"David" wrote:
I have an application that creates a database from a text file of DDL
(generated by Visio). Currently I have to deploy the text file with my
application and open it using the statement: SQL =
My.Computer.FileSystem.ReadAllText("CreateDB.SQL") .

This works fine, but I would prefer not to have to deploy a separate text
file, and I would like to prevent the users from having access to this file.

Is there some way to easily embed the text file into the compiled
executable? If there is, I will also need to know how to open and read from
an embedded file.

May 10 '06 #3
Thanks Jayeldee. I must have been posting my own reponse at the same time you
posted yours. I think we have the same approach but VS2005 allowed me to cut
a few corners.

"jayeldee" wrote:
David,

You can add the file to your project, then set its Build ACtion to
'Embedded Resource' through the IDE. You can then access it using a
function like the one below (there may be a cleaner way but this is
what I've used for similar files in the past)

Note: The FileName variable will be "[NameSpace].[FileName]" where
NameSpace is the namespace of your project (if you have one defined) in
the project properties. I just wrote up a console app and I had to use
"ConsoleApplication3.TextFile1" to stream it.

Function GetFileContents(ByVal FileName As String) As String

Dim this As [Assembly]
Dim fileStream As IO.Stream
Dim streamReader As IO.StreamReader
Dim strContents As String
this = System.Reflection.Assembly.GetExecutingAssembly
fileStream = this.GetManifestResourceStream(FileName)
streamReader = New IO.StreamReader(fileStream)
strContents = streamReader.ReadToEnd
streamReader.Close()
Return strContents

End Function

May 10 '06 #4
Sounds a lot easier to do in 2005.

May 10 '06 #5

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

Similar topics

4
38214
by: Samir Talwar | last post by:
Hi there. I'm writing a web site for my dad and I'm trying to embed text from an external file into the document - I need a frames section and a non-frames section and when one is changed it would...
3
2217
by: M | last post by:
Hi Folks, Does anyone know how to embed a file into a resource in C#? You seem to be able to embed Icon, Bitmap, Cursor's & Strings. But how do you embed a file??? In VC++ version 6 you...
10
4498
by: Yogi_Bear_79 | last post by:
pardon my ignorance as I am a self-taught hobbyist programmer. I am curious after reading up on SharpZipLib. Can I embed a zipped txt file in my program? Then either read from within the zip...
1
1966
by: Guoqi Zheng | last post by:
I have an ASP.NET application, I need to distribute it to clients. I used some text file to stroed database scripts, .sql files. Those .sql files are very very important part of the application,...
2
3287
by: Mark1249 | last post by:
Hello, I am using ASP.NET 2 and using the CreateUserWizard I am wanting an email to go out to the new user informing them of their account details etc... I have a BodyFileName in the...
5
1687
by: Ivan Debono | last post by:
Hi, I have an asp file that as a URL variable. The variable contains the url to another htm file. How can I embed the htm file within the body of the asp file? Thanks, Ivan
1
1632
by: Jon Paal | last post by:
trying to embed a text file as a resource when compiling with vbc.exe /resource: "readme.txt" error returned is asking for <resinfo> what is "<resinfo" and what is correct command line...
2
2966
by: Robert | last post by:
Dear all, I want to embed a motorola s file in my exe file using Visual C++.net, and then I can use the data in the Motorola file. How should I do? I am urgently need your help. Thanks a lot.
1
1863
by: vjunkl | last post by:
Hello, I have a content text file in my project and I'd like to copy it to a folder at some point in the execution of the application(not during a build). If this is not possible, how about...
0
7129
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7333
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7398
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...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.