GetResource
Reads embeded files from your executable programs (such as xml, images, etc.) Allows you to distribute one program - the exe, but still access your data and images needed with the program.
AI
AIサマリー: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
ソースコード
Public Function GetResource(ByVal filename As String) As System.IO.Stream
' Demo Instructions:
'
' Add an XML document to your project called "test.xml"
'
' Click the file and under properties, set BuildAction to "Embedded Resource"
'
' paste this routine in one of your classes or forms.
'
' Add the import to the top of your class
' Imports System.Xml.XmlDocument
'
' Dim the XML Document object
' Dim xmldoc As XmlDocument = New XmlDocument()
'
' Load the XML document from the resource
' xmldoc.Load(GetResource("test.xml"))
'
' Congratulations. You have learned how to embed files within
' your program and read them at run-time
'
Dim oAssembly As Reflection.Assembly = MyClass.GetType.Assembly
Dim sFiles() As String
Dim sFile As String
' prefix filename with namespace
filename = oAssembly.GetName.Name & "." & filename
' get a list of all embeded files
sFiles = oAssembly.GetManifestResourceNames()
' loop through each file
For Each sFile In sFiles
' found the file? return the stream
If sFile = filename Then
Return oAssembly.GetManifestResourceStream(sFile)
End If
Next
End Function
オリジナルのコメント (3)
Wayback Machineから復元