Compiler building options to import a text file to show it in a richtextbox for example during running time in visual studio 2019?

Dietrich 1 Reputation point

I have a text file and want to intregate the text into the code
and show during the running time it in a Richtextbox.

Like: Richtextbox.Loadfile("help.txt")
The hepl.txt is a part of the resourcefiles.

The compiler shall import the whole text file during the building process.
How can I do this in visual studio 2019?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,458 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tianyu Sun-MSFT 27,801 Reputation points Microsoft Vendor

    Hi @Dietrich ,

    What do you mean about integrating the text into the code?

    If you just want to show the content of the text file to the richtextbox, you can use codes like richTextBox1.Text = File.ReadAllText("File Path");.

    If you mean import(copy, move) the file to the specific folder(directory) before Build and during the application run, display the file into a richtextbox, you can try to add a Pre-build event. Right-click your project > choose Properties > Build Events > Pre-build event command line: > use Macros and add commands like copy $(TargetDir)*.txt $(ProjectDir), then add codes in Windows Forms like richTextBox1.Text = File.ReadAllText("File Path");

    Or you can edit your csproj file(right-click your project > Unload Project > right-click your project > Edit Project File)

    Add codes like

    <Target Name="BeforeBuild">  
        <Copy SourceFiles="$(OutputPath)XXX.txt" DestinationFolder="$(Your variable)" />  

    Best Regards,

    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    0 comments No comments