Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

how to i display a text document inside a window on my program without having the text file be a separet file. what i mean is there a way to have the text file within the program and have it display it some how when called. If u cant have it within the program how do u display the text file from a separet file?

 

Ps. How do i create a text document with variables? like"window1 Title = "windowtitle" and add/subtract/call those variables?

Edited by starcraft
  • Leaders
Posted

well you can include a textfile in your project , but it will get stored in the program's folder anyway , but here's how to read from a textfile on your HD to a textbox :

   Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
       Dim f As IO.File
       Dim path As String = "C:\test.txt"
       If f.Exists(path) Then '/// check if the text file exsists.
           Dim sRead As IO.StreamReader = New IO.StreamReader(New IO.FileStream(path, IO.FileMode.Open))
           While Not sRead.Peek
               TextBox2.AppendText(sRead.ReadLine & Environment.NewLine) '/// read the text file 1 line at a time , in to a textbox.
           End While
           sRead.Close()
       Else
           MessageBox.Show("oops check you put the correct file path!")
       End If
   End Sub

  • Leaders
Posted

also you can use a richtextbox to open the file with a very small amount of code :

   Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
       If IO.File.Exists("C:\test.txt") Then
           RichTextBox1.LoadFile("C:\test.txt", RichTextBoxStreamType.PlainText)
       End If
   End Sub

  • *Experts*
Posted

You can embed your text file into the exe, but you will only be able to read the text file, wont be able to write to it.

 

Add the file to your solution, go to your soltuion explorer and click on it once, down in the properties window you should see a Build Action property, set it to Embeded Resource. Now you text file will be compiled into the exe.

Then to read it do this:

Dim reader As New IO.StreamReader(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("RootNamespace.FileName.txt"))

This will retrieve the file for you to read.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...