How to add a custom text file to a visual studio project?

I am creating a text input application and would like to add text files to the project containing various commonly used words that can later be read. However, when I go to Project → Add Existing Item, it is possible to add VB files to the project. Is there a way to add text files to the project or do I have to import data from the file at runtime?

+5
source share
1 answer

Project Resource (Resx) Version:

With this version you will find it easier to work with your example!

  • Right click on your project
  • Select "Properties"
  • Go to resources section
  • , .
  • "" DropDown.
  • " ".
  • " ".

Resx resources

- ...

Dim content As String = My.Resources.mytextfile

. , !

:

  • .
  • - > .
  • ( ).
  • " (*. *)"
  • .
  • .

Select All Files

, (), () " ". , .

  • . ( , ) Application.GetContentStream(uri). , AssemblyAssociatedContentFile , VS , ""
  • : .

; fooobar.com/questions/12410/...

Embedded Resource, , :

Dim executing_assembly As System.Reflection.Assembly = _
    Me.GetType.Assembly.GetEntryAssembly()

' Get our namespace.
Dim my_namespace As String = _
    executing_assembly.GetName().Name.ToString()

' Load a text file.
Dim text_stream As Stream = _
    executing_assembly.GetManifestResourceStream(my_namespace _
    + ".text1.txt")
If Not (text_stream Is Nothing) Then
    Dim stream_reader As New StreamReader(text_stream)
    Label1.Text = stream_reader.ReadToEnd()
    stream_reader.Close()
End If

: http://www.vb-helper.com/howto_net_embedded_resources.html

+13

All Articles