G
Guest
I am attempting to embed a text resource in my assembly and following MSDN
article
http://msdn.microsoft.com/library/d...mactiontocreatedatabaseduringinstallation.asp
using reflection to access the full path of the embedded resource. The
assembly name is MyCompany Database Translator which is correctly reported
using [Assembly].GetExecutingAssembly().GetName().Name. Here is the code
supplied to get access to the embedded resource:
Private Function GetSql(ByVal Name As String) As String
Try
' Gets the current assembly.
Dim Asm As [Assembly] = [Assembly].GetExecutingAssembly()
' Resources are named using a fully qualified name.
Dim strm As Stream = Asm.GetManifestResourceStream(Asm.GetName().Name
+ "." + Name)
' Reads the contents of the embedded file.
Dim reader As StreamReader = New StreamReader(strm)
Return reader.ReadToEnd()
Catch ex As Exception
MsgBox("In GetSQL: " & ex.Message)
Throw ex
End Try
End Function
Using the method above fails because it tried to load MyCompany Database
Translator.textfile.txt, the resource is actually stored at
MyCompany_Database_Translator.textfile.txt with underscores in place of the
spaces. Is there another property I can access to get the correctly formatted
assembly path or is a string.replace the only way to address this? Thank you.
article
http://msdn.microsoft.com/library/d...mactiontocreatedatabaseduringinstallation.asp
using reflection to access the full path of the embedded resource. The
assembly name is MyCompany Database Translator which is correctly reported
using [Assembly].GetExecutingAssembly().GetName().Name. Here is the code
supplied to get access to the embedded resource:
Private Function GetSql(ByVal Name As String) As String
Try
' Gets the current assembly.
Dim Asm As [Assembly] = [Assembly].GetExecutingAssembly()
' Resources are named using a fully qualified name.
Dim strm As Stream = Asm.GetManifestResourceStream(Asm.GetName().Name
+ "." + Name)
' Reads the contents of the embedded file.
Dim reader As StreamReader = New StreamReader(strm)
Return reader.ReadToEnd()
Catch ex As Exception
MsgBox("In GetSQL: " & ex.Message)
Throw ex
End Try
End Function
Using the method above fails because it tried to load MyCompany Database
Translator.textfile.txt, the resource is actually stored at
MyCompany_Database_Translator.textfile.txt with underscores in place of the
spaces. Is there another property I can access to get the correctly formatted
assembly path or is a string.replace the only way to address this? Thank you.