Solved

Save checkedListBox file list to USB drive

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

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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
linq, c# 8 52
VB.NET - Refactor Class per SOLID principles 2 43
itextsharp with c# 3 35
Inserting LocalDB Table to SQL Server C# 3 51
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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