【问题标题】:Inserting Selected Item on Specific Folder在特定文件夹中插入所选项目
【发布时间】:2013-10-25 02:58:34
【问题描述】:

我有 2 个按钮(Button1 - 浏览;Button2 - 上传)和 1 个文本框

这里是场景。当我单击浏览时,它将打开一个窗口并浏览特定项目。 所选项目将显示在文本框上。

private void Browse_Click(object sender, EventArgs e)
{
    btnSample.Title = "Sample File Upload";
    btnSample.InitialDirectory = @"c:\";
    btnSample.Filter = "TIF|*.tif|JPG|*.jpg|GIF|*.gif|PNG|*.png|BMP|*.bmp|PDF|*.pdf|XLS|*.xls|DOC|*.doc|XLSX|*.xlsx|DOCX|*.docx";
    btnSample.FilterIndex = 2;
    btnSample.RestoreDirectory = true;
    if (btnSample.ShowDialog() == DialogResult.OK)
    {
        textBox1.Text = btnSample.FileName;
    }
}

当我单击上传按钮时,文本框中的文件将位于创建的文件夹中。 我已完成创建文件夹。但我的问题是如何在文件夹中插入所选文件。

private void button4_Click(object sender, EventArgs e)
{
    string path = @"C:\SampleFolder\NewFolder";
    if (!Directory.Exists(path))
    {
        Directory.CreateDirectory(path);
        MessageBox.Show("Successfully Created New Directory");
    }
    else
    {
        MessageBox.Show("Filename Exist");
    }
}

【问题讨论】:

    标签: c# winforms create-directory


    【解决方案1】:
    var sourceFilePath = @"C:\temp\file.txt";
    var destFilePath= @"C:\otherFolder\file.txt";
    

    如果你想move文件:

    File.Move(sourceFilePath, destFilePath);
    

    如果你想copy文件

    File.Copy(sourceFilePath, destFilePath);
    

    简单吧? 当然,您必须根据问题调整路径...

    【讨论】:

      猜你喜欢
      • 2016-12-06
      • 2018-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-09
      相关资源
      最近更新 更多