Computer Help and Spyware Removal Computer Help and Spyware Removal Computer Help and Spyware Removal Computer Help Forums Windows Startup Programs Database Virus, Spyware, and Malware Removal Guides Computer Tutorials Uninstall Database File Database Computer Glossary Computer Resources
 

Welcome Guest ( Log In | Click here to Register a free account now! )



Register a free account to unlock additional features at BleepingComputer.com
Welcome to Bleeping Computer, 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.

 
Reply to this topicStart new topic
> VB .Net, Embedded text files, and assemblies
aommaster
post Jun 18 2009, 10:33 AM
Post #1


I !<3 malware
******

Group: HJT Senior Classmen
Posts: 1,834
Joined: 8-June 08
From: Ontario
Member No.: 214,918



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 hysterical.gif.

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

My code is as follows:
CODE
        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?:
CODE
Dim startfileName As String = "folder 1.folder 2.Startofhtml.txt"


Thanks again


--------------------
Go to the top of the page
 
+Quote Post
Billy O'Neal
post Jun 18 2009, 12:15 PM
Post #2


Look buddy -- I'm an Engineer
******

Group: HJT Team Coach
Posts: 8,510
Joined: 17-January 08
From: Northfield, Ohio
Member No.: 184,215



You can use My.Resources in Visual Basic smile.gif

Billy3


--------------------
Go to the top of the page
 
+Quote Post
aommaster
post Jun 18 2009, 12:26 PM
Post #3


I !<3 malware
******

Group: HJT Senior Classmen
Posts: 1,834
Joined: 8-June 08
From: Ontario
Member No.: 214,918



Hi Billy!

Thanks for your reply. Is this another (programmatically correct) way of doing it?
CODE
        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?


--------------------
Go to the top of the page
 
+Quote Post
Billy O'Neal
post Jun 24 2009, 12:48 PM
Post #4


Look buddy -- I'm an Engineer
******

Group: HJT Team Coach
Posts: 8,510
Joined: 17-January 08
From: Northfield, Ohio
Member No.: 184,215



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.

This post has been edited by Billy O'Neal: Jun 24 2009, 12:50 PM


--------------------
Go to the top of the page
 
+Quote Post
aommaster
post Jun 24 2009, 01:04 PM
Post #5


I !<3 malware
******

Group: HJT Senior Classmen
Posts: 1,834
Joined: 8-June 08
From: Ontario
Member No.: 214,918



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 smile.gif

Thanks again Billy smile.gif


--------------------
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 21st November 2009 - 09:29 AM


Advertise   |   About Us   |   Terms of Use   |   Privacy Policy   |   Contact Us   |   Site Map   |   Chat   |   Tutorials   |   Uninstall List
Discussion Forums   |   The Computer Glossary   |   Resources   |   RSS Feeds   |   Startups   |   The File Database   |   Virus Removal Guides

© 2003-2009 All Rights Reserved Bleeping Computer LLC.