473,471 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Extracting files in .net

Echooff3
22 New Member
Here's a function I created to write embedded resource files into whatever file you need it to go. I used it to retrieve an embedded word document and write it to a temp folder.

Expand|Select|Wrap|Line Numbers
  1. Public Sub CreateFileFromResourceFile(ByVal pIn As String, ByVal pOut As String)
  2.         Dim currAssembly As Reflection.Assembly
  3.  
  4.         Dim input As Stream
  5.         Dim output As Stream
  6.         Dim Buffer(20000) As Byte
  7.         Dim read As Integer
  8.  
  9.         currAssembly = System.Reflection.Assembly.GetEntryAssembly()
  10.  
  11.         input = currAssembly.GetManifestResourceStream(pIn)
  12.  
  13.         output = New FileStream(pOut, FileMode.Create, FileAccess.Write, FileShare.Write)
  14.         input.Seek(0, SeekOrigin.Begin)
  15.  
  16.         read = input.Read(Buffer, 0, 20000)
  17.  
  18.         While read > 0
  19.             output.Write(Buffer, 0, read)
  20.             read = input.Read(Buffer, 0, 20000)
  21.         End While
  22.  
  23.         input.Close()
  24.         output.Close()
  25.  
  26.     End Sub
  27.  
  28.  
USEAGE:
pIn : String that represents the embedded resource
pOut : Where you want the file written

If you need to find the names of your embedded resources, in the immediate window type in:
Expand|Select|Wrap|Line Numbers
  1. ?System.Reflection.Assembly.GetEntryAssembly.GetManifestResourceNames
  2.  
That will list all your resources by name.
Jul 9 '07 #1
1 1235
GrantAtSerialKeyMaker
1 New Member
I took your code sample, and expanded it to answer a question posted in the archives on how to access and use an embedded DLL reference (http://bytes.com/forum/thread226160.html).

Once you have the embedded resource name using the method you showed, you can then stream the data and create an object to use.

objStream = p_asmExecutingAssembly.GetManifestResourceStream(s trEmbeddedResourceName)

I created a helper class to make this easier:
EmbeddedAssemblyHelper.rename_to_vb.txt

Then, when you want to access the object, you create an instance of it, and invoke any of it's methods.

I created a walkthrough and sample project here:
Serial Key Maker Blog: May - DLL Embedding

Grant
http://www.serialkeymaker.com
Effortless License Key Protection for .Net Applications
May 25 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Nazgul | last post by:
Hi! I want to implement a small tool in Python for distributing "patches" and I need Your advice. This application should be able to package all files chosen by a user into a self-extracting.exe...
2
by: Avi | last post by:
hi, Can anyone tell me what the problem is and how to solve it The following piece of code resides on an asp page on the server and is used to download files from the server to the machine...
0
by: Nadav | last post by:
Hi, Introduction: *************************** I am using the MSI API to extract MSI embedded files, I do this by iterating through all of the records in the ‘_Streams’ table and dumping...
3
by: wenz | last post by:
Hi I have an exe which is actually a self-extracting zip file that i would like to run to extract all the files. I have the code showing how to use the j# classes and library to extract zip files...
2
by: Dickyb | last post by:
Extracting an Icon and Placing It On The Desktop (C# Language) I constructed a suite of programs in C++ several years ago that handle my financial portfolio, and now I have converted them to...
0
by: k_nil | last post by:
I have a link on my web page for a self extracting executable file placed on the server. When the link is clicked, 1) i could see dialog box with open or save options 2) when open clicked, self...
2
by: Robert McEuen | last post by:
Sorry if this double-posts...Google doesn't do a very good job of communicating whether something has posted or not. Using Access 97, WindowsXP Is there a way to pass command line parameters...
2
by: bjm | last post by:
I created a self extracting zip file with about 9000 files in it. I extracted it manually from the command line without a problem. However, when I tried to do the same extraction at the same...
6
by: Werner | last post by:
Hi, I try to read (and extract) some "self extracting" zipefiles on a Windows system. The standard module zipefile seems not to be able to handle this. False Is there a wrapper or has...
4
by: Ant | last post by:
Hi all, My kids have a bunch of games that have to be run from CD (on Windows XP). Now they're not very careful with them, and so I have a plan. I've downloaded a utility (Daemon Tools) which...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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
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
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...
0
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.