Results 1 to 16 of 16

Thread: [VB2005] [RESOLVED] Attach file to application

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2007
    Posts
    174

    Resolved [VB2005] [RESOLVED] Attach file to application

    Hey everyone,
    so concept is simple, I have been trying to attach a file to my application.
    I would like a simple button that when I click on it the file gets saved on the drive.

    In order to do this I went in properties of my project, then resources then added the file.

    I added my button:
    Code:
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            
            ExportAssembly("my_file_name", "C:")
    End Sub
    ExportAssembly takes the name of my file, as well as the path.


    The function is a per below:

    Code:
     Public Sub ExportAssembly(ByVal name As String, ByVal folder As String)
    
            Dim myAssembly As System.Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
            Dim myStream As Stream = myAssembly.GetManifestResourceStream(myAssembly.GetName.Name + "." + name)
            Dim byteExeFile(myStream.Length) As Byte
            MessageBox.Show(myStream.Length)
    
            myStream.Read(byteExeFile, 0, myStream.Length)
            Dim myTempFile As FileStream = New FileStream(folder + "\" + name, FileMode.Create)
            myTempFile.Write(byteExeFile, 0, myStream.Length)
            myTempFile.Close()
    
    
        End Sub
    So it's pretty straigh forward, declaring the stream reading the resource file and writing it on the drive...

    The problem is that when I run the program at the line "Dim byteExeFile(myStream.Length) As Byte" I get the following error:

    "NullReference Exception was unhandelled"
    "Object reference not set to an instance of an object."

    I have tried many things I also have on top of my code
    Imports System
    Imports System.IO
    Imports System.Text

    ...
    it's been frustrating because I had such a hard time starting and finding about these information to link a file but right now I am stuck...
    is there something that I am missing ??

    Thanks for any help
    Last edited by Zoroxeus; Jan 3rd, 2008 at 10:23 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width