复制任意格式文件到指定目录
//复制文件到指定目录 private void btnFileCopy_Click(object sender, RoutedEventArgs e) { //弹出文件选择框 点击确定后开始复制文件 var open = new System.Windows.Forms.OpenFileDialog { Multiselect = false }; if (open.ShowDialog() == Forms.DialogResult.OK) { string f = open.FileName; //获得文件后缀 string extStr = Path.GetExtension(f); string NewGuid = TType.NewGuidStr(); //File.Copy(源文件地址,目标地址, true(为true是覆盖同名文件)); File.Copy(f, Path.Combine(Environment.CurrentDirectory + @"\TestImages\", NewGuid + extStr), true); } } //复制之前最好先检查是否存在目的目录 没有则创建 if (!Directory.Exists(p2)) Directory.CreateDirectory(p2);
posted on 2011-06-01 17:36 MichaelZhao 阅读(416) 评论(1) 编辑 收藏 举报