我在将文件从服务器复制到本地计算机时收到“无法找到路径的一部分”错误。这是我的代码示例:
try
{
string serverfile = @"E:\installer.msi";
string localFile = Path.GetTempPath();
FileInfo fileInfo = new FileInfo(serverfile);
fileInfo.CopyTo(localFile);
return true;
}
catch (Exception ex)
{
return false;
}
谁能告诉我我的代码有什么问题。
最佳答案
Path.GetTempPath
返回文件夹路径。您还需要指定文件路径。你可以这样做
string tempPath = Path.GetTempPath();
string serverfile = @"E:\installer.msi";
string path = Path.Combine(tempPath, Path.GetFileName(serverfile));
File.Copy(serverfile, path); //you can use the overload to specify do you want to overwrite or not
关于c# - 找不到部分路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18566176/