Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have to make a program that reads a TXT file in the folder where my program is and has to update it through textbox1.text and textbox2.text.

**My question is:**
I have 2 text boxes, which are filled out with entries etc. by the user.

These data or entries of 2 text boxes (textbox1.text & textbox2.text) should be saved in the same folder in the LOGS.TXT file. All entries entered subsequently in text boxes must also be saved as a new line, so what has been entered in these two text boxes so far must not be lost

At the end it has to be checked whether these entries have already existed, because if so, the program has to say that it doesn't work because either Textbox1.Text has already saved something in LOGS.TXT and/or Textbox2.Text (preferably with IF and else function)

Can you help me please. I'm relatively new to C# and I can't find anything on YouTube etc. at all! :/

What I have tried:

C#
string strTheFile = File.ReadAllText(@"LOGS.TXT"); //Read the TXT LOG FILE to check DUPLICATE

           if (strTheFile.Contains(trackingcodetxt.Text + rechnungsnummertxt.Text + Environment.NewLine))
           {
               MessageBox.Show("ERROR! Enteries allready exist", "Auto-Check | V1.0.0", MessageBoxButtons.OK, MessageBoxIcon.Error);
           }
           else {
           int stringLength = (int)laengeupdown.Value; // IF ALL OK GENERATE THE FILE
           trackingcodetxt.Text = "B2B" + GetRandomString(stringLength);

           string folderPath = Path.Combine(this.pfadtxt.Text, this.trackingcodetxt.Text + ".txt");
           using (StreamWriter sw = new StreamWriter(folderPath))
           {
               sw.WriteLine(";" + this.trackingcodetxt.Text + ";;;;;;;;;;;;;;;;;;;;;" + this.rechnungsnummertxt.Text + ";" + this.datenbankcombobox.Text);

               MessageBox.Show("Erfolgreich", "Auto-Save | V1.0.2", MessageBoxButtons.OK, MessageBoxIcon.Information);
               clearbtn.Enabled = true;
               infolabel.Text = "Erfolgreich: " + rechnungsnummertxt.Text;
               infolabel.ForeColor = Color.DarkGreen;
Posted
Updated 17-Oct-22 15:13pm
v2
Comments
OriginalGriff 17-Oct-22 23:59pm    
"Can you help me please."

Help you with what? You haven't asked a question, just posted your assignment!
What have you tried?
Where are you stuck?
What help do you need?

What does the code you show do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.

Use the "Improve question" widget to edit your question and provide better information.
Member 15627495 18-Oct-22 0:08am    
rewrite the using scope. as you're in a ELSE statement, you can let the streamwriter before launch a messagebox.

to put a string at last position when writing a file : append / flush
Member 15627495 18-Oct-22 2:09am    
when you're in your IDE visual studio, select a keyword in your code, then press F1.
It's for Microsoft Help page online. try it.

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