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.Fil eSystem.ReadAll Text("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. 4 6512
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
"ConsoleApplica tion3.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.Reflecti on.Assembly.Get ExecutingAssemb ly
fileStream = this.GetManifes tResourceStream (FileName)
streamReader = New IO.StreamReader (fileStream)
strContents = streamReader.Re adToEnd
streamReader.Cl ose()
Return strContents
End Function
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.Cr eateDB
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.Fil eSystem.ReadAll Text("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.
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 "ConsoleApplica tion3.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.Reflecti on.Assembly.Get ExecutingAssemb ly fileStream = this.GetManifes tResourceStream (FileName) streamReader = New IO.StreamReader (fileStream) strContents = streamReader.Re adToEnd streamReader.Cl ose() Return strContents
End Function
Sounds a lot easier to do in 2005. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 be so much
easier if I didn't have to go through the code to change the content
every time my dad changed something. Any way to embed text?
Thanks,
Samir Talwar
|
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 would, Find the Resource, Load It, get its size, and
then write it out to where ever you want it.
|
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 file or unzip and read
it? I currently have an embedded text file that contains a list that is
read into an array. I'm always looking to save space. And I could reduce my
file size 75% if it was zipped! I have looked at the SharpZipLib web site,...
|
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, I like to
hide them from clients.
Is there a way to embed those .sql text file into the compiled .dll file? so
that client can not read it???
|
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 MailDefinition section of the
CreateUserWizard component and have that currently pointing to a simple
text file where I want to embed the account detail variables and email
text.
| |
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
|
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 format required to add a text file as a resource ??
|
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.
|
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 reading a content text file into a
string. This will do the job just as well, maybe better.
Thanks in advance.
Vince
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |