Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

VB .Net, Embedded text files, and assemblies


  • Please log in to reply
4 replies to this topic

#1 aommaster

aommaster

    I !<3 malware


  • Malware Response Team
  • 5,294 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Dubai
  • Local time:02:45 PM

Posted 18 June 2009 - 10:33 AM

Hi guys!

I'm new to VB .Net (I can do the basic things like writing up functions, and simple events) and I decided to add a function to a piece of already-written code.

I have a text file in the root of the project which I have set as "embedded resource", which I believe is a step in the right direction :thumbsup:.

I'd like to input the whole text file's contents into a string.

My code is as follows:
Dim startfileName As String = "Startofhtml.txt"
		Dim Asm As System.Reflection.[Assembly] = System.Reflection.[Assembly].GetExecutingAssembly()
		Dim strm As Stream = Asm.GetManifestResourceStream(Asm.GetName().Name.ToString() + "." + startfileName)
		Dim reader As StreamReader = New StreamReader(strm)
		Dim preview As String = reader.ReadToEnd()

My problem is with line 4 of the above code when it says that StreamReader is trying to read a null value. Now, I'm guessing that it's hit a problem with trying to use the resource, so I'm guessing I haven't done something right with respect to finding the namespace. However, I'm not sure.

Also, say I put this startofhtml.txy in folder 2, which is located in folder 1 which is located in the root. Do I define the startfilename as follows?:
Dim startfileName As String = "folder 1.folder 2.Startofhtml.txt"

Thanks again

My website: http://aommaster.com
unite_blue.png
Please do not send me PM's requesting for help. The forums are there for a reason : )
If I am helping you and do not respond to your thread for 48 hours, please send me a PM


BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:03:45 AM

Posted 18 June 2009 - 12:15 PM

You can use My.Resources in Visual Basic :thumbsup:

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 aommaster

aommaster

    I !<3 malware

  • Topic Starter

  • Malware Response Team
  • 5,294 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Dubai
  • Local time:02:45 PM

Posted 18 June 2009 - 12:26 PM

Hi Billy!

Thanks for your reply. Is this another (programmatically correct) way of doing it?
Dim res() As String = GetType(Form1).Assembly.GetManifestResourceNames()
		Dim stream As System.IO.Stream = GetType(Form1).Assembly.GetManifestResourceStream(res(0))
		Dim stream_reader As New StreamReader(stream)

		Dim preview As String = stream_reader.ReadToEnd()

Or is this not a correct technique to apply in such a case?

My website: http://aommaster.com
unite_blue.png
Please do not send me PM's requesting for help. The forums are there for a reason : )
If I am helping you and do not respond to your thread for 48 hours, please send me a PM


#4 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:03:45 AM

Posted 24 June 2009 - 12:48 PM

You can.... it's just easier to use the My. namespace IMHO. So long as your code works I don't think there's much of a difference. Using My. just has Visual Basic take care of the nasty work for you.

Billy3

EDIT: Though I have not tested the above code.

Edited by Billy O'Neal, 24 June 2009 - 12:50 PM.

Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#5 aommaster

aommaster

    I !<3 malware

  • Topic Starter

  • Malware Response Team
  • 5,294 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Dubai
  • Local time:02:45 PM

Posted 24 June 2009 - 01:04 PM

Hi Billy!

Yeah, the code that I initially wrote worked, although the res index number kept changing. I finally figured out how to you the My.Res properties and am using that now, since yes, they are a lot easier to take care of :thumbsup:

Thanks again Billy :flowers:

My website: http://aommaster.com
unite_blue.png
Please do not send me PM's requesting for help. The forums are there for a reason : )
If I am helping you and do not respond to your thread for 48 hours, please send me a PM





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users