I am trying to copy one image from one location to another location using File.Copy() function but it gives the process can not access exception,any one can please help on this bellow is the code block.I have attached screenshot for exception.
private void btnUpload_Click(object sender, EventArgs e)
{
string SourcePath;
string RootDrive;
string DestPath;
string fileName;
fileName = "";
try
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Title = "Select Image to Upload";
ofd.Filter = "Jpg|*.jpg|Jpge|*.jpge|Gif|*.gif";
ofd.FileName = null;
if (ofd.ShowDialog() != DialogResult.Cancel)
{
fileName = ofd.FileName;
}
ofd.Dispose();
DestPath = Directory.GetCurrentDirectory() + @"\Uploads\PropertyImages\";
string destFile = System.IO.Path.Combine(DestPath, fileName);
if (!System.IO.Directory.Exists(DestPath))
{
System.IO.Directory.CreateDirectory(DestPath);
}
System.IO.File.Copy(fileName, destFile, true);
}
catch (Exception ae)
{
MessageBox.Show(ae.Message, "Upload Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}