我使用下面的代码行将内容从远程目录复制到本地缓存,但是这样做时我得到一个正在使用的文件异常。 以下是我的代码:
File.Copy(srcPath, srcPath.Replace(AppConfig.ConfigFolderLocation, LocalCachePath), true);
LocalCachePath似乎正在使用中。
整个代码:
if (Directory.Exists(LocalCachePath))
{
foreach (var srcPath in Directory.GetFiles(AppConfig.ConfigFolderLocation))
{
//Copy the file from sourcepath and place into mentioned target path,
//Overwrite the file if same file is exist in target path
File.Copy(srcPath, srcPath.Replace(AppConfig.ConfigFolderLocation, LocalCachePath), true);
}
}
else
MessageBox.Show("Directory Doesn't exists! Please create one");