Пример #1
0
        private void btnUpload_Click(object sender, RoutedEventArgs e)
        {
            string sourcePath = this.srcFile.Text.Trim();
            string destDir    = AppDomain.CurrentDomain.BaseDirectory + "DataTemplates\\" +
                                cbTemplateType.SelectedValue.ToString();

            if (!File.Exists(sourcePath))
            {
                MessageBox.Show("请选择模板!");
                return;
            }


            if (!Directory.Exists(destDir))
            {
                Directory.CreateDirectory(destDir);
            }
            string destPath = destDir + "\\" + System.IO.Path.GetFileName(sourcePath);

            if (File.Exists(destPath))
            {
                string           messageBoxText = "模板已经存在,要覆盖吗?";
                MessageBoxButton button         = MessageBoxButton.YesNo;
                MessageBoxResult result         = MessageBox.Show(messageBoxText, "提示", button);
                if (result == MessageBoxResult.No)
                {
                    return;
                }
            }

            this.btnUpload.IsEnabled = false;
            ///copy file and nodify ui that rate of progress of file copy
            this.copyFlag.Text = "开始上传...";
            //设置进度条最大值
            this.copyProgress.Maximum = (new FileInfo(sourcePath)).Length;
            //保存复制文件信息,以进行传递
            CopyFileInfo c = new CopyFileInfo()
            {
                SourcePath = sourcePath, DestPath = destPath
            };

            //线程异步调用复制文件
            copyThread = new Thread(new ParameterizedThreadStart(CopyFile));
            copyThread.Start(c);
        }
Пример #2
0
        /// <summary>
        /// 上传文件的委托方法
        /// </summary>
        /// <param name="obj">复制文件的信息</param>
        private void CopyFile(object obj)
        {
            CopyFileInfo c = obj as CopyFileInfo;

            CopyFile(c.SourcePath, c.DestPath);
        }