troubleshooting Question

How can I edit the text in a text file with a TextBox?

Avatar of mrcoulson
mrcoulsonFlag for United States of America asked on
C#ASP.NET
11 Comments2 Solutions246 ViewsLast Modified:
I have a text file.  I want to load the text file in a text box, make changes, and save the changes by clicking submit.  I can load the file with no problem, but the changes do not seem to be taking effect.  I am attaching all of my C# code.  Where have I gone wrong?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.IO;
 
namespace CancellationsManager
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            display_cancellations();
        }
 
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
 
            insert_cancellations();
 
            lblSuccess.Visible = true;
 
            // Reset TextBoxes.
            foreach (Control control in form1.Controls)
            {
                if (control is TextBox)
                {
                    ((TextBox)control).Text = String.Empty;
                }
            }
 
            display_cancellations();
        }
 
 
        public void insert_cancellations()
        {
            StreamWriter sw = new StreamWriter(Server.MapPath("text/cancellations.txt"));
            sw.Write(txtCancelField.Text);
            sw.Close();
        }
 
        public void display_cancellations()
        {
            StreamReader sr = new StreamReader(Server.MapPath("text/cancellations.txt"));
            txtCancelField.Text = sr.ReadToEnd();
            sr.Close();
        }
 
    }
}
ASKER CERTIFIED SOLUTION
kumar754

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 11 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros