5 Replies - 885 Views - Last Post: 27 June 2011 - 12:10 PM Rate Topic: -----

#1 MadeToFail  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-June 11

Using a .txt file in a directory in solution

Posted 20 June 2011 - 12:51 PM

Hello everyone,
I've been trying to retrieve the contents of a .txt file that's in a directory in the solution. Here's a little image of what I mean:
Posted Image (assume the name of the solution is "TestName", not that it should make any difference)
This is what I've got so far:
Public Sub CreateDB()
    MsgBox(GetSolutionFile("abilities\abilities.txt"))
End Sub

Private Function GetSolutionFile(ByVal name As String) As String
    Dim a As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom(Application.ExecutablePath)
    Dim s As System.IO.Stream = a.GetManifestResourceStream("DB\" + name)
    Dim b As Byte() = New Byte() {}
    s.BeginRead(b, 0, s.Length, Nothing, s)
    Return System.Text.Encoding.Unicode.GetString(B)/> ' <- should be b, but this thing capitalizes it automatically...
End Function



Thanks in advance.
Kind regards,
MadeToFail

This post has been edited by MadeToFail: 20 June 2011 - 12:53 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Using a .txt file in a directory in solution

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9224
  • View blog
  • Posts: 34,630
  • Joined: 12-June 08

Re: Using a .txt file in a directory in solution

Posted 20 June 2011 - 12:54 PM

So what is the problem? Are you getting an exception? If so what does it say? What line is it breaking on? Perhaps you are getting functionality you were not expecting. What is happening that shouldn't? What should be happening?

Please help us to help you by posting a question and explaining what is going on. We aren't over your shoulder so we have to make due!
Was This Post Helpful? 0
  • +
  • -

#3 MadeToFail  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-June 11

Re: Using a .txt file in a directory in solution

Posted 20 June 2011 - 12:56 PM

Ah sorry, I forgot to tell you. ^^"
Well, the thing is. I don't get anything. I see nothing, and nothing happens, even not an empty MessageBox.
And of course, I do call the ModuleName.CreateDB().

This post has been edited by MadeToFail: 20 June 2011 - 12:58 PM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9224
  • View blog
  • Posts: 34,630
  • Joined: 12-June 08

Re: Using a .txt file in a directory in solution

Posted 20 June 2011 - 01:04 PM

Mkay that's not overly helpful. Do you know how to debug your application? Put a break point on a line and step through each line to see what is going on with the variables? If yes then what did that yeild? If not here's a tutorial to help you with this skill.

Debugging

Over all I am not sure what is going on with your code. Why are you using reflection? Why not the stream reader? You are aware "GetManifestResourceStream" is for embedded images and what not. From what I can tell you just have a file in a folder in the solution folder. That's not embedded. Embedded is more like things put in the resource tab of the project's properties. What you have is a plain old file not an embedded resource.


Quote

^ ^"
Eh, what?

This post has been edited by modi123_1: 20 June 2011 - 01:05 PM

Was This Post Helpful? 0
  • +
  • -

#5 MadeToFail  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-June 11

Re: Using a .txt file in a directory in solution

Posted 20 June 2011 - 01:07 PM

Ah okay. This is my first time I want to retrieve something from the solution, so yeah... Well, I just searched some code to get started of, but if that doesn't work... Well, I'll look at that tomorrow, because I got to go now. I'll edit my post/post a reply when I checked that. Thanks.

And ^ ^" is just some kind of smiley.

This post has been edited by MadeToFail: 20 June 2011 - 01:07 PM

Was This Post Helpful? 0
  • +
  • -

#6 samuel17  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 209
  • Joined: 14-October 10

Re: Using a .txt file in a directory in solution

Posted 27 June 2011 - 12:10 PM

Hi MadeToFail,
If you are just looking to put a txt file contents in a label or something like that, i did something just like that on a project i was doing. Here is what i did:
openFile.Title = "Select Text File"
        openFile.ShowDialog()
        Dim sr As New StreamReader(openFile.FileName)
        theFile = sr.ReadToEnd
        FileTextBox.Text = theFile


I used a open file dialog to select the file which will be different since it is in your application folder. I then used streamreader, read in that file, assigned it to a variable "theFile", and then made the text box i had equal to "theFile". So basically, it reads the file and puts it in the textbox. Hope this helps some.

Sam
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1