Advertisement
Java_Volume1 Files #103175

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.

ซอร์สโค้ด
original-source
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