【问题标题】:C#: OpenFileDialog copy a file [closed]C#:OpenFileDialog 复制文件 [关闭]
【发布时间】:2012-12-16 07:16:17
【问题描述】:

您好,我有一个带有此代码的按钮:

     OpenFileDialog ofd = new OpenFileDialog();
        string percorso = Environment.CurrentDirectory;
        percorso += @"\img\Articoli";
        ofd.InitialDirectory = percorso;
        ofd.Filter = "File JPEG/JPG (*.jpeg *.jpg)|*.jpg;*.jpeg|File PNG (*.png)|*.png;|Tutti i files (*.*)|*.*"; 
        if (ofd.ShowDialog() == DialogResult.OK)
        {
            tPercorso.Text = System.IO.Path.GetFileName(ofd.FileName);
            Refresh_Image();
        }       

我需要当我在 OpenFileDialog 中选择一个文件时,如果他的路径不等于“percorso”,则会出现一个 MessageBox:“你想复制默认路径中的文件吗?”是 |否,如果 DialogResult == YES 我需要将此文件复制到路径“percorso”并仅像我正在做的那样选择文件名。 你能帮助我吗? 问候。

【问题讨论】:

  • 在对话框关闭之前使用 FileOk 事件拒绝路径。

标签: c# image path openfiledialog file-copying


【解决方案1】:

如果您只关心复制文件,请查看File.Copy。如果要使用标准 shell 进度对话框复制文件,请查看 this related question

您还应该查看Path.Combine

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多