- Joined
- Feb 19, 2010
- Messages
- 158
- Reaction score
- 174
Offline
What can I do to resolve this error: "The process cannot access the file because it is being used by another process?"
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace SuperiorFileMaintance
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/*
*
* ///////BROWSE BUTTON//////
*
*/
private void browseButton_Click(object sender, EventArgs e)
{
FolderBrowserDialog fld = new FolderBrowserDialog();
fld.ShowNewFolderButton = true;
DialogResult result = fld.ShowDialog();
if (result == DialogResult.OK)
{
browseDisplay.Text = fld.SelectedPath;
Environment.SpecialFolder root = fld.RootFolder;
}
}
/*
*
* ///////MOVE BUTTON///////
*
*/
private void moveTo_Click(object sender, EventArgs e)
{
string source = browseDisplay.Text;
string destination = moveTo.Text;
try
{
foreach (string fileName in Directory.GetFiles(source))
{
File.Copy(Path.Combine(source, fileName), Path.Combine(destination, fileName), true);
}
}
catch (IOException exp)
{
MessageBox.Show(exp.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
/*
*
* ///////DESTINATION BUTTON///////
*
*/
private void dButton_Click(object sender, EventArgs e)
{
FolderBrowserDialog fld = new FolderBrowserDialog();
fld.ShowNewFolderButton = true;
DialogResult result = fld.ShowDialog();
if (result == DialogResult.OK)
{
moveToDisplay.Text = fld.SelectedPath;
Environment.SpecialFolder root = fld.RootFolder;
}
}
}
}