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 7840063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:38:55+00:00 2026-06-02T15:38:55+00:00

Ok I have been working on this for many days and I know I

  • 0

Ok I have been working on this for many days and I know I am getting close to finishing it up but I keep getting errors. The first error I got was a ArgumentException was unhandledwhich was at this:

else
{
    using (StreamWriter sw = File.AppendText(path))<--This is where is says 
    Argument exception was unhandled.              
    {    
        foreach (var item in employeeList.Items)
            sw.WriteLine(item.ToString());
    }

ok so I fixed it with this:

try
{    
    StreamWriter sw = File.AppendText(path);
    foreach (var item in employeeList.Items)
        sw.WriteLine(item.ToString());
}
catch
{
    MessageBox.Show("Please enter something in");
}

Ok now I am getting the error

of Invalid Cast Exception Unable to cast object of type
‘WindowsFormsApplication2.Employee’ to type ‘System.String’.

On this line:

string path = txtFilePath.Text;    

if (File.Exists(path))
{
    using (StreamWriter sw = File.CreateText(path))
    {   
        foreach (string line in employeeList.Items)<-- Right here at the string line
            sw.WriteLine(line);
    }
}

I have done moved the try and catch around and I keep getting errors. All I want to do with the save button is write the selected record to the file specified in the txtFilePAth without truncating the values currently inside. But I want to be able to have a message that comes across if you push the button without having something in that box it pops up.And yes I know there is not a specific path that is due to the user be able to save the file wherever they want too. Can someone please help me understand what I am doing wrong.

  • 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-02T15:38:57+00:00Added an answer on June 2, 2026 at 3:38 pm

    employeeList.Items returns you a list of the data items the list is bound to. This is not a list of strings, but a list of Employee objects (this seems to be a class you’ve defined somewhere in your application). So the syntax that would work is:

    foreach (Employee employee in employeeList.Items)
    {
        // do something with the employee object
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on this for days but I don't get it so
Hi For many days I have been working on this problem in MySQL, however
I've been working on this problem for a few hours and have used many
Have been working on this question for a couple hours and have come close
I have been working on this problem for 2 days now and it's an
I have been working on this issue for a few days now and can't
Hi I have been trying to get this script http://jsbin.com/ipajo5/ working but using .live()
I have been working on this for a while. Tried many many different things,
So I have been working on this for some time. Would like to know
I have been working on this for a couple of days and am quite

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.