C# 在特定文件夹中插入选定项目
我有两个按钮(按钮1-浏览;按钮2-上传)和一个文本框 下面是一个场景。当我点击Browse时,它会打开一个窗口并浏览特定的项目。 所选项目将显示在文本框中C# 在特定文件夹中插入选定项目,c#,winforms,create-directory,C#,Winforms,Create Directory,我有两个按钮(按钮1-浏览;按钮2-上传)和一个文本框 下面是一个场景。当我点击Browse时,它会打开一个窗口并浏览特定的项目。 所选项目将显示在文本框中 private void Browse_Click(object sender, EventArgs e) { btnSample.Title = "Sample File Upload"; btnSample.InitialDirectory = @"c:\"; btnSample.Filter = "TIF|*.
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");
}
}
如果要删除该文件,请执行以下操作:
File.Move(sourceFilePath, destFilePath);
如果你想删除这个文件
轻松,嗯?
当然,你必须根据你的问题调整路径
File.Move(sourceFilePath, destFilePath);
File.Copy(sourceFilePath, destFilePath);