Bra*_*ley 1 c# asp.net visual-studio-2010
我有一个循环的XML文件集合,并将有错误的文件移动到另一个文件位置.但是,当我使用system.io.file.move函数时,它需要我指定文件名而不是移动文件路径.有没有办法可以将文件从一个位置移动到另一个位置,同时保持相同的名称?我目前正在根据数组中文件的位置创建一个名称,这是不可行的.
string ErrorPath = string.Format(@"{1}ErroredXml{0}.xml", errorLength, errorPaths);
//If type equals "add" then call add method else call update
if (Equals(type, typecomp))
{
//pass object to data access layer to add record
value.addNewGamePlay();
if (value.getGamePlayID() == 0)
{
//move to error file
System.IO.File.Move(value.getFile(), ErrorPath);
errorLength++;
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用以下Path.GetFileName
方法提取原始文件名并使用它构造目标路径Path.Combine
:
var original = value.getFile();
var destinationPath = Path.Combine(errorPaths, Path.GetFileName(original));
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1824 次 |
最近记录: |