Results 1 to 5 of 5

Thread: Text File in project

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    Text File in project

    Hey. I added a text file in my project and set it as an embedded resource. How would I go about doing a 'msgbox' on everything that's in that text file?

    Thanks
    John

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Text File in project

    VB Code:
    1. Dim str As New IO.StreamReader(IO.File.OpenRead("FileName"))
    2.         MessageBox.Show(str.ReadToEnd)
    3.         str.Close()
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Text File in project

    Are you using VB 2005? Please specify in future.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    May 2005
    Posts
    181

    Re: Text File in project

    hmm im using 2003. The thing is that the text file is an actual embedded resource. It's not on the computer, it's part of the project. I want the forum to be able to access it when it's all compiled into the .exe. This is kinda like accessing embedded pictures.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Text File in project

    In VB 2005 it is so easy a retarded lump of coal could do it. You add the file as a resource on the Resources tab of the project properties and at run time you do this:
    VB Code:
    1. Dim fileContents As String = My.Resources.ResourceName
    In earler versions you have to work a bit harder.
    VB Code:
    1. Dim thisExe As System.Reflection.Assembly
    2. thisExe = System.Reflection.Assembly.GetExecutingAssembly()
    3. Dim file As System.IO.Stream = _
    4.     thisExe.GetManifestResourceStream("WindowsApplication4.StackTrace.txt")
    5. Dim sr As New IO.StreamReader(file)
    6.  
    7. MessageBox.Show(sr.ReadToEnd())
    8. sr.Close()
    That code is adapted from this example. I used a project named WindowsApplication4 and a file named StackTrace.txt. You'll obviously have to change those to whatever is appropriate in your case.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width