我有一个TextBox(txtDocUpload)和一个Button。点击该按钮后,上传对话框正在打开,上传文件后我必须将其保存在特定文件夹中。
用于打开上传对话
private void txtBtnUpload_Click_1(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
//openFileDialog.DefaultExt = ".txt";
Nullable<bool> result = openFileDialog.ShowDialog();
if (result == true)
{
filename = openFileDialog.FileName;
txtDocUpload.Text = System.IO.Path.GetFileName(filename);
}
}
单击保存按钮我必须保存,代码(&#34; File1&#34;是我要保存文件的位置)。
string urlpath = "WoDocs";
var path = @"~\" + urlpath + @"\" + WOMaintenance.GetAddressId.IDWorkOrderDetail;
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
var ext = System.IO.Path.GetExtension(txtDocUpload.Text);
var pathURL=txtDocDescription.Text+ext;
var file1 = System.IO.Path.Combine(path,txtDocDescription.Text + ext);
//docFile1.SaveAs(file1);
答案 0 :(得分:0)
这是一个简短的例子:
private void CopyAFile()
{
var source = new OpenFileDialog();
if (source.ShowDialog().GetValueOrDefault())
{
var dest = new SaveFileDialog();
if (dest.ShowDialog().GetValueOrDefault())
{
File.Copy(source.FileName, dest.FileName);
}
}
}
这应该表明当您有权访问源位置和目标位置时,File.Copy可以正常工作。