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:
ExportAssembly takes the name of my file, as well as the path.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
The function is a per below:
So it's pretty straigh forward, declaring the stream reading the resource file and writing it on the drive...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
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




Reply With Quote