Question add a file from resources to temp file location

skitz

Member
Joined
May 8, 2009
Messages
15
Programming Experience
Beginner
Read is not a member of byte array

ok im tryin to run an embedded .exe in my app but i seem to be having a issue with my code can someone have a look and tell me what my issue is ? :eek:


VB.NET:
Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
        Dim size As Long = My.Resources.Myprogram.Length - 1
        Dim buffer(CInt(size)) As Byte
        Dim offset As Integer = 0
        Dim count As Integer = CInt(size)
        Dim returnValue As Integer
      [U] returnValue = My.Resources.Myprogram.Read(buffer, offset, count)[/U]
        Dim fs As New] IO.FileStream(IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.Temp, "Myprogram.exe"), IO.FileMode.Create)
        fs.Write(buffer, 0, buffer.Length)
        fs.Close()
    End Sub

my error is ' Read ' is not a member of 'system Array'. i have change the program name to Myprogram i have added myprogram.exe and then the 'exe' is not a member of 'system array' am i doing something compleatly wrong i have had help with the code so far as im only a beginner :eek:
 
Yes, I'm afraid you are doing something completely wrong. You cannot execute a file from your resources because your resources doesn't contain files. If you have embedded an executable file as a resource then My.Resources is going to return that as a Byte array containing the binary contents of the file. That's why you're getting an error message saying you can't call Read on an array.

If what you're trying to do is save that resource as a file then the easiest way is like this:
VB.NET:
IO.File.WriteAllBytes("file path here", My.Resources.Myprogram)
 
What im trying to do as it's embedded in my app, i want to make a temp folder and run that .exe from a button_click event
 
VB.NET:
Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
IO.File.WriteAllBytes("file path here", My.Resources.Myprogram)
IO.Path.GetTempPath
    End Sub

Something like that as i only a beginner and i think im getting a little lost sorry
 
GetTempPath returns the path of the temp folder. You use that to build the path of the file you want to save. You then pass that file path to WriteAllBytes and it will write to that file.
 
Hi i am trying to add a file to temp file location

i have a EXE running from a button_click event the EXE has a file needed to run with this EXE i have embedded this file as a resource but i need to add it to the temp file that my EXE run's from how do i go about getting this file to run to the temp file location

do i have to code it from my main form ?

i have tried to explain the best i can sorry if im unclear
 
Back
Top