本文介绍了将文件从一个地方复制到另一个地方时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件从一个地方复制到另一个地方,这是代码.

i am trying to copy a file from one place to another here is the code.

private void button1_Click(object sender, EventArgs e)
{
    OpenFileDialog openFileDialog2 = new OpenFileDialog();
    openFileDialog2.InitialDirectory = @"C:\";
    openFileDialog2.Title = "Browse Text Files";
    openFileDialog2.CheckFileExists = true;
    openFileDialog2.CheckPathExists = true;

if (openFileDialog2.ShowDialog() == DialogResult.OK)
   {
       textBox2.Text = openFileDialog2.FileName;
   }
string filename,filex;
   filex = openFileDialog2.SafeFileName;

   filename = textBox2.Text;
   string dpath = @"D:\G\"+ filex ;
   File.Copy(filename, dpath );


但这给了我以下错误
文件``D:\ G \ openFileDialog2''已经存在.
请告诉我代码有什么问题.


but it gives me the follwoing error
The file ''D:\G\openFileDialog2'' already exists.
please tell me whats wrong with the code.

推荐答案


这篇关于将文件从一个地方复制到另一个地方时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 06:50