Click here to Skip to main content
Email Password   helpLost your password?
Screenshot of App

Introduction

To use this, you'll need to add three controls to the Toolbox that Microsoft has disabled by default. They are amazing controls that simplify the workload of this project by a lot.

They are DriveListBox, DirListBox, and FileListBox. Simply go to Tools > Choose Toolbox Items > and check DriveListBox, DirListBox, and FileListBox. Once done, add them and go to your design view. Add the three new controls to your project (arrange to look good).

Using the Code

Using ListBoxes

private void driveListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    try
    {
        dirListBox1.Path = driveListBox1.Drive;
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error : " + ex.Message, 
                        "Error", 
                        MessageBoxButtons.OK, 
                        MessageBoxIcon.Error);
    }
}
 private void dirListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    try
    {
        fileListBox1.Path = dirListBox1.Path;
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error : " + ex.Message,
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
    }
}
 private void fileListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    string fullPath = fileListBox1.Path + "\\" + fileListBox1.FileName;
    try
    {
        sr = new StreamReader(fullPath);
        richTextBox1.Text = sr.ReadToEnd();
        textBox1.Text = fullPath;
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error : " + ex.Message,
        "Error",
        MessageBoxButtons.OK,
        MessageBoxIcon.Error);
    }
}

Copy File

private void button2_Click(object sender, EventArgs e)
{
    sr.Close();
    try
    {
        File.Copy(fileListBox1.Path + "\\" + fileListBox1.FileName,
                  dirListBox2.Path + "\\" + fileListBox1.FileName, true);
         richTextBox1.Clear();
        richTextBox1.Text += "Copy Succeeded\n";
     }
    catch (Exception ex)
    {
        MessageBox.Show("Error : " + ex.Message,
        "Error",
        MessageBoxButtons.OK,
        MessageBoxIcon.Error);
    }
}

Delete File

private void button1_Click(object sender, EventArgs e)
{
    try
    {
        DialogResult dr;
        dr = MessageBox.Show("Are you sure you wish to delete " + 
			fileListBox1.FileName + "?",
                        "Confirmation",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question);
        if (dr == DialogResult.No)
            return;
        sr.Close();
        File.Delete(fileListBox1.Path + "\\" + fileListBox1.FileName);
        fileListBox1.Refresh();
        dirListBox1.Refresh();
        dirListBox2.Refresh();
        driveListBox1.Refresh();
        driveListBox2.Refresh();
        richTextBox1.Clear();
        richTextBox1.Text += "Delete Succeeded";
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error : " + ex.Message,
        "Error",
        MessageBoxButtons.OK,
        MessageBoxIcon.Error);
    }
}

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralPause copy
NeCroFire
4:13 26 Jan '09  
I wanted to know if there is any way to pause the copy of a file. Say your copying a 500MB file and want to pause it for some reason with a button click or something. How would one be able to do this?

Thanks Smile
GeneralThank you!!
Admin887
7:56 14 Aug '08  
Thank you!!
Questionproblem in file deletion
Neetu Maheshwari
0:17 22 Feb '08  
hello i m deleting a file but it is giving the error that "The process cannot access the file 'D:\MyDataBase\106.jpg' because it is being used by another process."
if (PicName != null)
{
if (File.Exists(DBPicPath))
{
if (File.GetAttributes(DBPicPath) == FileAttributes.ReadOnly)
File.SetAttributes(DBPicPath, FileAttributes.Normal);

File.Delete(DBPicPath);
}
File.Copy(PicName, completePath, true);
}
plzzz help me....
AnswerRe: problem in file deletion
dragan.jovanoski
0:41 4 Aug '08  
Try garbage collecting after Delete/Copy operation. It should work.

cheers
QuestionFile List box
Marshall S Porter
13:28 6 Jul '07  
I thought this was good, quick and fairly easy. I was going to use it to do some copying, but I found out this doesn't work if the file extentions aren't reconised and sence what I wanted to copy wasn't just the run of the mill files, but some self made files with extentions that didn't fall in the windows expected extentions.:(
Thanks though for the idea.
GeneralPretty
sk8er_boy287
22:40 31 May '07  
This looks pretty and all but it's not really useful. And if it were, the little preview window in the bottom-right corner would be kind of annoying. I wouldn't want to look at my code in a 3x3-inch box.Roll eyes
GeneralNot Too Bad
MatrixCoder
20:31 31 May '07  
Not too bad. But File/Dir/Drive boxes haven't been used since .NET 1.1, and you can easily replace them using standard ListBoxes and ComboBoxes. It's really pretty easy.

Just some constructive criticism. Good job anyway!



Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.


Last Updated 1 Jun 2007 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010