Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7866553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:25:58+00:00 2026-06-03T00:25:58+00:00

I been having trouble trying to figure this out. When I think I have

  • 0

I been having trouble trying to figure this out. When I think I have it I get told no. Here is a picture of it.
enter image description here

I am working on the save button. Now after the user adds the first name, last name and job title they can save it. If a user loads the file and it comes up in the listbox, that person should be able to click on the name and then hit the edit button and they should be able to edit it. I have code, but I did get inform it looked wackey and the string should have the first name, last name and job title.

It is getting me really confused as I am learning C#. I know how to use savefiledialog but I am not allowed to use it on this one. Here is what I am suppose to be doing:

When the user clicks the “Save” button, write the selected record to
the file specified in txtFilePath (absolute path not relative) without
truncating the values currently inside.

I am still working on my code since I got told that it will be better file writes records in a group of three strings. But this is the code I have right now.

    private void Save_Click(object sender, EventArgs e)
    {

            string path = txtFilePath.Text;


            if (File.Exists(path))
            {
                using (StreamWriter sw = File.CreateText(path))
                {

                    foreach (Employee employee in employeeList.Items)
                        sw.WriteLine(employee);
                }
            }
            else
                try
            {

                StreamWriter sw = File.AppendText(path);

                foreach (var item in employeeList.Items)
                    sw.WriteLine(item.ToString());

            }

    catch
{
    MessageBox.Show("Please enter something in");
}

Now I can not use save or open file dialog. The user should be able to open any file on the C,E,F drive or where it is. I was also told it should be obj.Also the program should handle and exceptions that arise.

I know this might be a noobie question but my mind is stuck as I am still learning how to code with C#. Now I have been searching and reading. But I am not finding something to help me understand how to have all this into 1 code. If someone might be able to help or even point to a better web site I would appreciate it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:25:59+00:00Added an answer on June 3, 2026 at 12:25 am

    There are many, many ways to store data in a file. This code demonstrates 4 methods that are pretty easy to use. But the point is that you should probably be splitting up your data into separate pieces rather than storing them as one long string.

    public class MyPublicData
    {
      public int id;
      public string value;
    }
    
    [Serializable()]
    class MyEncapsulatedData
    {
      private DateTime created;
      private int length;
      public MyEncapsulatedData(int length)
      {
         created = DateTime.Now;
         this.length = length;
      }
      public DateTime ExpirationDate
      {
         get { return created.AddDays(length); }
      }
    }
    
    class Program
    {
      static void Main(string[] args)
      {
         string testpath = System.IO.Path.Combine(
            Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "TestFile");
    
         // Method 1: Automatic XML serialization
         // Requires that the type being serialized and all its serializable members are public
         System.Xml.Serialization.XmlSerializer xs = 
            new System.Xml.Serialization.XmlSerializer(typeof(MyPublicData));
         MyPublicData o1 = new MyPublicData() {id = 3141, value = "a test object"};
         MyEncapsulatedData o2 = new MyEncapsulatedData(7);
         using (System.IO.StreamWriter w = new System.IO.StreamWriter(testpath + ".xml"))
         {
            xs.Serialize(w, o1);
         }
    
         // Method 2: Manual XML serialization
         System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(testpath + "1.xml");
         xw.WriteStartElement("MyPublicData");
         xw.WriteStartAttribute("id");
         xw.WriteValue(o1.id);
         xw.WriteEndAttribute();
         xw.WriteAttributeString("value", o1.value);
         xw.WriteEndElement();
         xw.Close();
    
         // Method 3: Automatic binary serialization
         // Requires that the type being serialized be marked with the "Serializable" attribute
         using (System.IO.FileStream f = new System.IO.FileStream(testpath + ".bin", System.IO.FileMode.Create))
         {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = 
               new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            bf.Serialize(f, o2);
         }
    
         // Demonstrate how automatic binary deserialization works
         // and prove that it handles objects with private members
         using (System.IO.FileStream f = new System.IO.FileStream(testpath + ".bin", System.IO.FileMode.Open))
         {
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf =
               new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            MyEncapsulatedData o3 = (MyEncapsulatedData)bf.Deserialize(f);
            Console.WriteLine(o3.ExpirationDate.ToString());
         }
    
         // Method 4: Manual binary serialization
         using (System.IO.FileStream f = new System.IO.FileStream(testpath + "1.bin", System.IO.FileMode.Create))
         {
            using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(f))
            {
               w.Write(o1.id);
               w.Write(o1.value);
            }
         }
    
         // Demonstrate how manual binary deserialization works
         using (System.IO.FileStream f = new System.IO.FileStream(testpath + "1.bin", System.IO.FileMode.Open))
         {
            using (System.IO.BinaryReader r = new System.IO.BinaryReader(f))
            {
               MyPublicData o4 = new MyPublicData() { id = r.ReadInt32(), value = r.ReadString() };
               Console.WriteLine("{0}: {1}", o4.id, o4.value);
            }
         }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having trouble trying to figure out how to properly convert the
I'm having trouble trying to figure out how to get prolog to spit out
I've been looking through related LINQ questions here trying to figure this one out,
Hello I have been having trouble with this for a while now. I have
I've been trying to figure this out for a few hours now. In order
I'm having trouble trying to figure out a way to return a GeoPoint with
I've been trying to figure this out all night, but I guess my knowledge
I've been trying to figure this one out by reading the git-svn man-page but
I'm having a bit of trouble trying to get this quicksort algorithm to work
I'm having trouble trying to figure out how to solve a dependency issue within

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.