Today we are going to present how to use embedded files in Visual Studio.
- Add your file into your project by right click on the project icon, then click on Add => Add Existing Item.
- Go to file properties, and choose the option "Build Action" to "Embedded Resrouce"
- Copy the following function that retrieve resources as Stream:
Public Function GetFileFromResource(ByVal FileName As String, ByVal ProjectName As String) As IO.Stream
Dim assmbly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
Dim stream As IO.Stream = assmbly.GetManifestResourceStream(ProjectName + "." + FileName )
Return stream
End Function - Now you have a stream connection with the resource that you want to deal with.
Exampe:
If you have a sample project "TestProj" with the embedded resource file "Capture.PNG"
Then you call the function as : GetFileFromResource("Capture.PNG", "TestProj")