在C#中移动文件时,不支持给定路径的格式错误? [英] The given path's format is not supported error during moving the file in C#?
问题描述
您好,
Hello,
The given path's format is not supported error during moving the file in c#
此行错误: -
error in this line:-
System.IO.File.Move(@"C:\PrintingDocument\" + file, @"C:\PrintedDocument\" + file);
这里也有一个问题,
我的进程在Windows服务中不起作用。
我想将文件夹移动到另一个文件夹但是它收到错误。
请帮帮我。
我们如何解决。
先谢谢。
Ankit Agarwal
软件工程师
我的尝试:
One problem is here also,
my process is not working in Windows Service.
I want to Move file one folder to another but its getting error.
Please help me.
How can we resolve.
Thanks in Advance.
Ankit Agarwal
Software Engineer
What I have tried:
string[] files = Directory.GetFiles(@"C:\PrintingDocument\");
foreach (string file in files)
{
//if (string.IsNullOrEmpty(file))
//{
// //txtFileName.BackColor = Color.Yellow;
// //MessageBox.Show("Please Select file.");
// return;
//}
if (File.Exists(file))
{
ProcessStartInfo info = new ProcessStartInfo(file);
info.Verb = "Print";
info.CreateNoWindow = true;
//info.UseShellExecute = false;
info.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(info);
//TraceService(@"C:\PrintingDocument\" + file);
//TraceService(@"C:\PrintedDocument\" + file);
System.IO.File.Move(@"C:\PrintingDocument\" + file, @"C:\PrintedDocument\" + file);
TraceService("Printed Successfully" + " " + DateTime.Now.ToString());
}
else
{
TraceService("Not File found" + " " + DateTime.Now.ToString());
}
}
推荐答案
参见Directory.GetFiles Method(System.IO) [ ^ ]:
See Directory.GetFiles Method (System.IO)[^]:
返回指定目录中文件的名称(包括它们的路径)。
Returns the names of files (including their paths) in the specified directory.
您的文件
变量不是单个文件名,而是完整路径。您必须从中提取文件名(请参阅路径.GetFileName方法(字符串)(System.IO) [ ^ ])。
示例:
Your file
variable is not a single file name but a complete path. You must extract the file name from it (see Path.GetFileName Method (String) (System.IO)[^] ).
Example:
string fileName = Path.GetFileName(file);
System.IO.File.Move(file, @"C:\PrintedDocument\" + fileName);
[/ EDIT]
这篇关于在C#中移动文件时,不支持给定路径的格式错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!