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

  • Home
  • SEARCH
  • 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 6135437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:28:47+00:00 2026-05-23T17:28:47+00:00

I have the following code: SaveFileDialog saveGC1File = new SaveFileDialog(); private void GCSavePlacementOneButton_Click(object sender,

  • 0

I have the following code:

SaveFileDialog saveGC1File = new SaveFileDialog();

private void GCSavePlacementOneButton_Click(object sender, EventArgs e)
{
    // Initialize the SaveFileDialog to specify the .txt extension for the file.
    saveGC1File.DefaultExt = "*.txt";
    saveGC1File.Filter = ".txt Files|*.txt|All Files (*.*)|*.*";
    saveGC1File.RestoreDirectory = true;

    try
    {
        string placementOneSave = placementOneListBox.Items.ToString();

        // Save the contents of the formattedTextRichTextBox into the file.
        if (saveGC1File.ShowDialog() == DialogResult.OK && saveGC1File.FileName.Length > 0)
            placementOneSave.SaveFile(saveGC1File.FileName, RichTextBoxStreamType.PlainText);

        // Throws a FileNotFoundException otherwise.
        else
            throw new FileNotFoundException();
    }

    // Catches an exception if the file was not saved.
    catch (Exception)
    {
        MessageBox.Show("There was not a specified file path.", "Path Not Found Error",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
}

However, using Visual Studio 2010, the line in the “if” loop that states:

"placementOneSave.SaveFile(saveGC1File.FileName, RichTextBoxStreamType.PlainText);"

Has a red line under the “SaveFile”.. I have used this code to save a file before and am unsure why it will not work for a ListBox.


QUESTIONS

  • How can I save a ListBox in a similar way to a RichTextBox?
  • Any way to edit this code to make it have the user choose where the ListBox will be saved?
  • 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-05-23T17:28:47+00:00Added an answer on May 23, 2026 at 5:28 pm

    ListBox does not provide a method to save all its items to a file. The code snippet showing how this can be done is available here:

    C# code to save text from listbox to a text file — SOLVED–

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: String inputFile = somefile.txt; FileInputStream in = new FileInputStream(inputFile);
I have following code private static ObservableCollection<myColor> myItems = new ObservableCollection<myColor>(); myItems.Add(new myColor(red)); When
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from
I have following code: $telnums = array(10, 20, 30); $obj = new StdClass(); $obj->telnums
I have following code in the form_Load function System.Windows.Forms.Timer newtimer = new Timer(); newtimer.Tick
I have following code on my site: backgroundImages[bg_img_path_b]=new Image(); backgroundImages[bg_img_path_b].src = bg_img_path_b; backgroundImages[bg_img_path_b].loaded=loading; //jQuery(backgroundImages[lastImage]).unbind('load.backgroundImages');
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I'm trying to use opengl in C#. I have following code which fails with
I have the following code in a web.config file of the default IIS site.

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.