Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Save checkedListBox file list to USB drive

Posted on 2009-05-13
Medium Priority
Last Modified: 2012-06-21
I am trying to save a list of files in my checkedListBox to a drive.

I have searched and attempted to use a number of examples on the web.  Including those listed in the Code section and many others.

What would be the easiest operation to run?
File.Copy(sourceFileName, strDrive, overwrite);
            // create a file stream, where "c:\\testing.txt" is the file path
            System.IO.FileStream fs = new System.IO.FileStream("saveFileDialog1.FileName", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write, System.IO.FileShare.ReadWrite);
            // create a stream writer
            System.IO.StreamWriter sw = new System.IO.StreamWriter(fs, System.Text.Encoding.ASCII);
            // write to file (buffer), where textbox1 is your text box
            // flush buffer (so the text really goes into the file)
            // close stream writer and file
            sw.Close(); fs.Close();
    // Store in a string array
            string[] drives = Environment.GetLogicalDrives();
            // Loop into the string array
            foreach (string strDrive in drives)
                // Add items (drives) to the list
            // Insert code to save a file.
            foreach (int indexChecked in checkedListBox1.CheckedIndices)
                // The indexChecked variable contains the index of the item.
                MessageBox.Show("Index#: " + indexChecked.ToString() + ", is checked. Checked state is:" +
                                checkedListBox1.GetItemCheckState(indexChecked).ToString() + ".");

Open in new window

Question by:pk4000
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

deadlyDev earned 500 total points
ID: 24516394
Just by modifying your code slightly...
// Insert code to save a file.
StringBuilder sb = new StringBuilder();            
            foreach (int indexChecked in checkedListBox1.CheckedIndices)
                // The indexChecked variable contains the index of the item.
                //MessageBox.Show("Index#: " + indexChecked.ToString() + ", is checked. Checked stateis:" 
                //+ checkedListBox1.GetItemCheckState(indexChecked).ToString() + ".");
                sb.AppendLine("Index#: " + indexChecked.ToString() + ", is checked. Checked state is:" + 
                checkedListBox1.GetItemCheckState(indexChecked).ToString() + ".");
System.IO.File.WriteAllText("File location on drive...", sb.ToString());

Open in new window


Author Closing Comment

ID: 31581069
Thanks, had to make some changes because of multiple Panels but it worked great!

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA:…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question