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

x
?
Solved

Save checkedListBox file list to USB drive

Posted on 2009-05-13
2
Medium Priority
?
638 Views
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
            sw.Write(txtDestination.Text);
 
            // flush buffer (so the text really goes into the file)
            sw.Flush();
 
            // 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
                checkedListBox2.Items.Add(strDrive.ToString());
            }
 
            // 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

0
Comment
Question by:pk4000
[X]
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
2 Comments
 
LVL 7

Accepted Solution

by:
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

0
 
LVL 1

Author Closing Comment

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

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: https://www.percona.com/resources/we…
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