473,509 Members | 6,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Resource Files in App

How would I load a file from a resource?

We have a 'PDF-like' file that is formatted for printing the our label forms
(it isn't quite like a PDF, but pretty close. It lets us enter text that
comes out as a barcode).

Anyway, the file often gets lost or deleted by someone fooling around with
the PC when they should not be.

To resolve this problem, I inserted the file under Project Properties >
Resources Files section.

I want something like:

File.Open(global::Project2.Properties.Resources.Fi le1)

Obviously, this will not compile.

Can I use the Resource object to store files that I can access in my
application? If so, how?
Oct 14 '08 #1
2 2841
If you have an embedded resource added to your project in the way you
described, you can access it through My.Resources.

For example, if the resource is called ThePDF you can access it as:

My.Resources.ThePDF

Files like PDFs get encoded in the resource as a byte array. The below bit
of code would extract the resource and save it to a real file (probably not
what you want).

Dim fs as As System.IO.FileStream = New System.IO.FileStream("ThePDF.pdf",
System.IO.FileMode.Create)
fs.Write(My.Resources.ThePDF, 0, My.Resources.ThePDF.Length)
fs.Close()
Chuck

"jp2msft" wrote:
How would I load a file from a resource?

We have a 'PDF-like' file that is formatted for printing the our label forms
(it isn't quite like a PDF, but pretty close. It lets us enter text that
comes out as a barcode).

Anyway, the file often gets lost or deleted by someone fooling around with
the PC when they should not be.

To resolve this problem, I inserted the file under Project Properties >
Resources Files section.

I want something like:

File.Open(global::Project2.Properties.Resources.Fi le1)

Obviously, this will not compile.

Can I use the Resource object to store files that I can access in my
application? If so, how?
Oct 14 '08 #2
Thanks! That was what I needed.

"Chuck D" wrote:
If you have an embedded resource added to your project in the way you
described, you can access it through My.Resources.

For example, if the resource is called ThePDF you can access it as:

My.Resources.ThePDF

Files like PDFs get encoded in the resource as a byte array. The below bit
of code would extract the resource and save it to a real file (probably not
what you want).

Dim fs as As System.IO.FileStream = New System.IO.FileStream("ThePDF.pdf",
System.IO.FileMode.Create)
fs.Write(My.Resources.ThePDF, 0, My.Resources.ThePDF.Length)
fs.Close()
Chuck

"jp2msft" wrote:
How would I load a file from a resource?

We have a 'PDF-like' file that is formatted for printing the our label forms
(it isn't quite like a PDF, but pretty close. It lets us enter text that
comes out as a barcode).

Anyway, the file often gets lost or deleted by someone fooling around with
the PC when they should not be.

To resolve this problem, I inserted the file under Project Properties >
Resources Files section.

I want something like:

File.Open(global::Project2.Properties.Resources.Fi le1)

Obviously, this will not compile.

Can I use the Resource object to store files that I can access in my
application? If so, how?
Oct 14 '08 #3

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

Similar topics

3
10365
by: J.Marsch | last post by:
Hello all: I am trying to build a resource dll that will house icons, and I'm afraid that I'm not having much luck reading it. Can you lend hand (or just point me to a good primer). Here's...
12
2032
by: bj7lewis | last post by:
I am working on a project I want to add a few files as resource to access(copy them to FS and use) at runtime. So far in VS.NET IDE, I Add Files to the project and set its Build Action to...
1
3146
by: Kaworu | last post by:
Hi, at first time I want to apologize for my English. I need to change the language of my app and I like to do it changin the caption of the controls in the resource.rc file, or having on...
3
1975
by: Jules | last post by:
i'm working with translators that just want to translate "web pages" and not deal with resource files. i'd like to have a file structure that looks sort of like this: / <- root directory where...
4
1850
by: TCook | last post by:
Hey All, I am building a solution which will have many strings that will need to be localized (i.e. strings for toolbars, strings for different WinForms, strings for messages and error messages,...
1
11102
by: Screenbert | last post by:
After finding nothing anywhere in google I am posting this so everyone can benefit by it. The formating is not pretty since I copied it from my word document, but you should benefit by it. ...
2
1997
by: Daniel | last post by:
I am just investigating on .resx and .resource files using asp.net. I am attempting to develop a webpage in Dreamweaver on an asp.net webserver. As i read around the net, using a .resource file...
1
1989
by: Bill Mell | last post by:
I would like to use compiled resource files in my web application that are not related to localization. The idea is to have a dll with resources that can be accessed by the website. I have no...
2
3507
by: Andrus | last post by:
I have resource files in different languages created by VCS 2005 Express. I want to use those files to translate reports at runtime. I have text to be translated as string. I think I need to...
2
8718
by: Nathan Sokalski | last post by:
I am attempting to create icons for controls I have created using VB.NET by using the System.Drawing.ToolboxBitmap attribute. I have managed to do this in C# by specifying the path to the *.ico...
0
7137
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
7347
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
7416
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
7073
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
3218
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...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1571
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 ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
bsmnconsultancy
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...

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.