Click here to Skip to main content
15,791,541 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello i am using text file which contains some paragraphs
the text file is like below text's contain
1. "People often say that motivation doesn't last. Well, neither does bathing -- that's why we recommend it daily." -Zig Ziglar
2. "Someday is not a day of the week." -Denise Brennan-Nelson
3. "Hire character. Train skill." -Peter Schutz
4. "Your time is limited, so don't waste it living someone else's life." -Steve Jobs
5. "Sales are contingent upon the attitude of the salesman -- not the attitude of the prospect." -W. Clement Stone
6. "Everyone lives by selling something." -Robert Louis Stevenson
7. "If you are not taking care of your customer, your competitor will." -Bob Hooey
8. "The golden rule for every businessman is this: Put yourself in your customer's place." -Orison Swett Marden
9. "If you cannot do great things, do small things in a great way." -Napoleon Hill

like these what i need is when i read the entirefile i need to display in text block if read a whole file and store in a list while display in text block i dont know how to break the line in between and to start from next line and what i need to do if i want to stop at 4th quotes or 5th.

What I have tried:

<TextBlock x:Name="ReviewBlock" Grid.Row="1" Margin="0,40,0,0" Width="500" Text="{Binding Review}" FontSize="14" FontWeight="Medium" Foreground="White" ></TextBlock>

.cs code is

public void ReviewReadng()
          // string filePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
          var MyList = new List<string>();
          string filePath = System.IO.Path.GetFullPath(System.IO.Path.Combine(System.Reflection.Assembly.GetExecutingAssembly().Location, @"../"));
          filePath += "Reviewfile.txt";
          if (File.Exists(filePath))
              // Reads file line by line
              StreamReader Textfile = new StreamReader(filePath);
              string line;

              while ((line = Textfile.ReadLine()) != null)

          String Review = MyList[0];
          ReviewBlock.Text = Review;
Updated 7-Jun-21 7:32am

1 solution

string readText = File.ReadAllText( path );
ReviewBlock.Text = readText;

File.ReadAllText Method (System.IO) | Microsoft Docs[^]

string[] readText = File.ReadAllLines(path);
foreach (string s in readText) {

File.ReadAllLines Method (System.IO) | Microsoft Docs[^]

Add an Environement.NewLine to a string when you want to add a line break.
Share this answer
Fazil13 8-Jun-21 12:35pm    
Thanks it works

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900