我有2个按钮(button1 -browse; 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:SampleFolderNewFolder";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
MessageBox.Show("Successfully Created New Directory");
}
else
{
MessageBox.Show("Filename Exist");
}
}
var sourceFilePath = @"C:tempfile.txt";
var destFilePath= @"C:otherFolderfile.txt";
如果要移动文件:
File.Move(sourceFilePath, destFilePath);
如果要复制文件
File.Copy(sourceFilePath, destFilePath);
简单吧?当然,您必须将路径适应您的问题...