我正在尝试复制一些文件:
private void DoCopy() {
string[] files = Directory.GetFiles(Application.StartupPath + "\\App_Data", "*.*", SearchOption.AllDirectories);
string sFtpToReadFileFrom = "ftp://<user>:<pass>@mysite.tk/updates/App_Data/";
string sPathToWriteFileTo = Application.StartupPath + "\\App_Data";
WebClient webClient = new WebClient();
webClient.Credentials = new NetworkCredential("user", "pass");
foreach (string s in files)
{
string fileName = Path.GetFileName(s);
string destFile = Path.Combine(sPathToWriteFileTo, fileName);
byte[] fileData = webClient.DownloadData(sFtpToReadFileFrom + fileName); //shows correct bytes
File.Copy(s, destFile, true);
}
}
确切的错误是:进程无法访问文件 'C:\AppLauncher\AppLauncher\bin\Debug\App_Data\firstFile',因为它正被另一个进程使用。
我在这里遵循了“MSDN How To”:http: //msdn.microsoft.com/en-us/library/cc148994.aspx
如果有人发现任何直接的危险信号,请告诉我。