Click here to Skip to main content
15,921,279 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi!

can someone help me. I will Read a File if the file contains starts with specific word or numbers.
If the file starts and ends with the numbers, READ FILE or not not read the file.


my code:
C#
private void button1_Click(object sender, EventArgs e)
        {
            //*Openfiledialog

            OpenFileDialog of = new OpenFileDialog();
            of.ShowDialog();
            textBox1.Text = of.FileName;
        }


here are the code to open file dialog and i have a textbox under the bar to read the file.
Posted
Updated 10-Mar-15 23:17pm
v3
Comments
John C Rayan 11-Mar-15 5:23am    
You mean file name contains specific word or numbers?
Member 11515578 11-Mar-15 5:49am    
this file contains word and numbers. i will read the text IF contains with "00" and end with "99", if not, i will not read the file.
John C Rayan 11-Mar-15 5:52am    
So it is not file name.? you have to open the file and read the first and last work inside the file contents. Right?
Member 11515578 11-Mar-15 5:54am    
yea... you have right.
OriginalGriff 11-Mar-15 5:35am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.

You could achieve this by using the following statements

File.ReadLines("file.txt").First().StartsWith();

File.ReadLines("file.txt").Last().EndsWith();


The advantage of ReadLines() is that it will not load the whole file into memory.
 
Share this answer
 
Use a TextReader[^].
 
Share this answer
 

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