Save checkedListBox file list to USB drive

Posted on 2009-05-13
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

Accepted Solution

deadlyDev earned 125 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ConsoleSql 1 34
fomat Json objects 6 28
Visual Studio 2013 debugging 2 35
Filename to be appended with DateTimeof Download 3 47
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

896 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now