Question Coping files from resources

gixslayer

Member
Joined
Nov 8, 2008
Messages
19
Programming Experience
Beginner
Hey, i'm like kinda making my own installer, creating directory's & registry stuff works fine. But now I need a method of copying files in my projects resources to the hard drive. Right now I use this:

VB.NET:
        Dim sWriter As IO.Stream
        Dim myAssem As Reflection.Assembly
        myAssem = Reflection.Assembly.GetExecutingAssembly()
        sWriter = myAssem.GetManifestResourceStream("GHU.exe")
        Dim x As Integer = 0
        Dim fFile As IO.FileStream = New IO.FileStream("C:\GHU.exe",IO.FileMode.OpenOrCreate)
        For x = 1 To sWriter.Length
            fFile.WriteByte(sWriter.ReadByte)
        Next
        fFile.Close()
        sWriter.Close()

Though it crashes on this line:

VB.NET:
        For x = 1 To sWriter.Length

With this error:

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="WHU_Installer"
StackTrace:
at WHU_Installer.MyModule.CopyFileFromResource(String FileNameInResource, String Location) in D:\PC\Programming\Coding\Langauges\VB\Projects\WHU_Installer\WHU_Installer\Form1.vb:line 94 at WHU_Installer.Form1.BackgroundWorker1_DoWork(Object sender, DoWorkEventArgs e) in D:\PC\Programming\Coding\Langauges\VB\Projects\WHU_Installer\WHU_Installer\Form1.vb:line 59 at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e) at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
InnerException:

Could anyone help me out on this? Thanks.
 
VB.NET:
My.Computer.FileSystem.WriteAllBytes("c:\path\GHU.exe", My.Resources.GHU, False)
 
Back
Top