利用反射访问类库中的文件路径并拷贝文件

public void CopyDataBase(int num)
{
string codeBase = Assembly.GetAssembly(typeof(DataSynchronizationTest)).CodeBase;
string appPath = codeBase.Replace(@"file:///", string.Empty);
appPath = appPath.Replace(@"/", @"\");
int indexBin = appPath.IndexOf("bin\\");
appPath = appPath.Substring(0, indexBin);
string localPath = appPath + "DbFiles\\" + DataBaseTestConfig.LocalDbFileName(num);
string serverPath = appPath + "DbFiles\\" + DataBaseTestConfig.ServerDbFileName(num);
string localDesPath = System.IO.Directory.GetCurrentDirectory() + "\\DbFiles\\" + DataBaseTestConfig.LocalDbFileName(num);
string serverDesPaht = System.IO.Directory.GetCurrentDirectory() + "\\DbFiles\\" + DataBaseTestConfig.ServerDbFileName(num);
File.Copy(localPath, localDesPath, true);
File.Copy(serverPath, serverDesPaht, true);
}

你可能感兴趣的:(String,File)