Groups | Blog | Home
all groups > dotnet faqs > march 2006 >

dotnet faqs : Extracting files from an EXE


Zagor
3/17/2006 8:14:26 PM
Hi All,
I have a small exe app ( basic a dialog box) that when lauched needs to
"copy" some files in a directory chosen by the user (within the dialog). I
cannot use an installation package because there are some particular tasks
to be done from the exe.
Anyhow I was wondering if it possibile to include files within the (C#)exe
and then extract them from the exe when launched...sort of an installation.
I was thinking to add them as resources but I do not know how to extract
them.

Please any hint will be appreciated

Thank you
Zagor

SStory
3/28/2006 12:26:19 PM
There is Zip genius software.

You can zip a file and then direct it unzip all files to a directory and
then run an exe if it is named Setup.exe.

That would get the files in a directory and then run your exe.

Otherwise, this sounds a lot like a virus.


[quoted text, click to view]

VJ
4/15/2006 6:39:58 PM
Are you looking to extract the embbedded files from the exe to extract when
your exe launches?.. If the answer is yes... then here is what you do... in
your code at you can do this..

string includeFileName = "MyApplication.MySapce.Trial.jpg";
string strNewPathToSave = @"C:\MyNewPath\Trial.jpg";

System.IO.Stream myFile
= System.Reflection.Assembly.GetManifestResourceStream(includeFileName);

if ( myFile== null )
return "Unable to read the License file."; //"Inspherion License file is
not valid. Please contact Inspherion Support";

System.IO.FileStream fs = System.IO.File.OpenWrite(strNewPathToSave);
try
{
// Save the File...
byte[] buffer = new byte[myFile.Length];
myFile.Read(buffer,0,(int)myFile.Length);
fs.Write(buffer,0,buffer.Length);
}
finally
{
fs.Close();
}

Remeber that.. the includeFileName has to be fully qualified with Namespace
used by the executable or assembly where the file is embbeded.

HTH
VJ

[quoted text, click to view]

AddThis Social Bookmark Button