Hi, I'm a bit rusty with my C# but I'm trying to write a program for this website I am making. It's just a little something to help me edit certain texts in my website faster than what I normally do. Anyway the program I am making, I want it so that when I press a button (the file will already be chosen ahead of time) the program will take a specifically predetermined section of text and load it to a richtextbox. Then the user can edit it to their liking and press another button to save the content back into the original file.
I've been researching a bit online and I'm still having a bit of trouble. I was able to scrap pieces of code elsewhere but they were only able to read the first line of specific single lines in a text file. I don't know if C# can open / read php or html files, I'm sure they can, it's been a while since I used it, but just for extra info I want to be opening up php, html, css files, simple files such as those for websites.
This is the code I got so far, but the program keeps crashing on me.
private void button1_Click(object sender, EventArgs e)
{
string index = thisapp + @"\" + "index.php";
if (File.Exists(index))
{
using (var sr = new StreamReader(index))
{
var textInBetween = new List<string>();
bool startTagFound = false;
while (!sr.EndOfStream)
{
var line = sr.ReadLine();
if (String.IsNullOrEmpty(line))
{
continue;
}
if (!startTagFound)
{
startTagFound = line.StartsWith("• Administrator: Nicu L. <br />");
continue;
}
bool endTagFound = line.StartsWith("• Website Dev: Reece D. <br />");
if (endTagFound)
{
richTextBox1.Text = line;
}
textInBetween.Add(line);
}
}
}
else if (File.Exists(index) == false)
{
MessageBox.Show("Index.php Could Not Be Found");
}
Thanks for anyone who can help me!!