C#路径问题_空路径名是非法的?
运用多线程进行文件复制,编译成功,复制时提示空路径名是非法的在System.Arguement Exception 中第一次偶然出现的"mscorlib.dll"类型的异常,但是我在下面不是已经结合了文件夹更文件名称了吗?提示空路径是/的转义字符的问题么? 就是把"C:\aa\bb"变为"C:\\aa\\bb"?应该怎么解决?
附上整个工程文件,求各位指出错误及解决方法..谢谢..
代码如下:
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Threading;
using
namespace CopyAssistant
{
public partial class Form1 : Form
{
string destFile;
string srcFile;
public Form1()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
string dstfname = Path.GetFileName(srcrtbox.Text);
string dsturl = (dstrtbox.Text,dstfname);
this.srcFile = srcrtbox.Text; // 要复制的源文件名称
this.destFile = dsturl; // 要复制到的目标文件名称
}
private void mainwindow_Click(object sender, EventArgs e)
{
if (mainwindow.Checked)
{
this.ShowInTaskbar = true;
this.Show(); //显示窗口
}
else
{
this.ShowInTaskbar = false;
this.Hide(); //隐藏窗口
}
}
private void exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
public void srcbtn_Click(object sender, EventArgs e)//选择源文件
{
if (opendlg.ShowDialog() == DialogResult.OK)
{
string srcpath = opendlg.FileName;//打开源文件
srcrtbox.Text = srcpath;//将源文件路径填写到srcrtbox中
}
}
private void src_menu_Click(object sender, EventArgs e)//选择源文件-菜单栏
{
if (opendlg.ShowDialog() == DialogResult.OK)
{
string srcpath = opendlg.FileName;//打开源文件
srcrtbox.Text = srcpath;//将源文件路径填写到srcrtbox中
}
}
private void dstbtn_Click(object sender, EventArgs e)//选择目标路径
{
if (folderdlg.ShowDialog() == DialogResult.OK)
{
string dstpath = folderdlg.SelectedPath;//打开目标文件夹
dstrtbox.Text = dstpath;//将目标路径填写到dstrtbox中
}
}
private void dst_menu_Click(object sender, EventArgs e)//选择目标路径-菜单栏
{
if (folderdlg.ShowDialog() == DialogResult.OK)
{
string dstpath = folderdlg.SelectedPath;//打开目标文件夹
dstrtbox.Text = dstpath;//将目标路径填写到dstrtbox中
}
}
private void exit_menu_Click(object sender, EventArgs e)//关闭窗口
{
this.Close();
}
void CopyProcess()
{
FileStream src = null, dest = null;
try
{
src = new FileStream(this.srcFile, FileMode.Open, FileAccess.Read, FileShare.Read);
dest = new FileStream(this.destFile, FileMode.Create, FileAccess.Write, FileShare.None);
long size = src.Length;
long currBytes = 0;
byte[] buffer = new byte[1024];
int length = 0;
do
{
length = src.Read(buffer, 0, buffer.Length);
currBytes += length;
this.pgrProgress.Value = (int)(currBytes * 100 / size);
dest.Write(buffer, 0, length);
}
while (length != 0);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if (src != null)
src.Close();
if (dest != null)
dest.Close();
this.Close();
}
}
private void cpbtn_Click(object sender, EventArgs e)//多线程&&断点续传
{
this.Show();
// 在此处创建多线程复制文件
Thread thread = new Thread(new ThreadStart(this.CopyProcess));
thread.IsBackground = true;
thread.Start();
}
}
}
[[it] 本帖最后由 jansongg 于 2008-6-30 11:15 编辑 [/it]]
[[it] 本帖最后由 jansongg 于 2008-6-30 11:15 编辑 [/it]]
[[it] 本帖最后由 jansongg 于 2008-6-30 11:19 编辑 [/it]]
CopyAssistant.rar
(50.12 KB)