我从本地服务器复制一个.txt的时候有问题。它抛出异常:
文件名,目录名或卷标语法不正确。
我想这可能是一些与路径格式,所以我试图通过向服务器路径的@:
@ Configuration.Manager [路径]
| @\\ SERVERPATH \ SharedFolder
我也试着用这种格式:\\ SERVERPATH \ SharedFolder ...他们没有工作
顺便说其不是接入问题,因为我一直试图做的运行命令提示符一样的东西从C#:
System.Diagnostics.Process.Start(cmd.exe的,/ C复制PATH1,PATH2); //这个工作和复制的文件。
我会很感激,如果有人能够给我的可能是什么问题就在这里了线索。做什么至少有一个建议。
在此先感谢和抱歉我的英文不好!
编辑:
这是的code应该工作的一部分:
字符串路径prevDay =D:\ AuditFiles \ enc_+ svr.Name +_counts+ day.AddDays(-1)的ToString(DD-MM -YY)+名.txt;
如果(File.Exists(路径prevDay))
{
File.Copy(路径prevDay,@ ConfigurationManager.AppSettings [MAIL_SERVER_PATH]);
}
解决方案
您需要逃脱反斜杠,并指示文件在File.Copy(路径prevDay,ConfigurationManager中的名称。的AppSettings [MAIL_SERVER_PATH]);
更改此:
字符串路径prevDay =D:\ AuditFiles \ enc_+ svr.Name +_counts+ day.AddDays(-1)的ToString(DD-MM -YY)+名.txt;
这样:
字符串路径prevDay =D:\\ AuditFiles \\ enc_+ svr.Name +_counts+ day.AddDays(-1)的ToString(DD -MM-YY)+名.txt;
您也可以使用单斜杠(/),而不是像这样的:
字符串路径prevDay =D:/ AuditFiles / enc_+ svr.Name +_counts+ day.AddDays(-1)的ToString(DD-MM -YY)+名.txt;
I'm having problems when copying a .txt from a local server ("D:\AuditFiles") to a shared folder in another server ("\\PrintServer\SharedFolder"). It throws the exception:
"The filename, directory name, or volume label syntax is incorrect."
I thought it could be something with the path format, so I tried by adding to the server path an @:
@Configuration.Manager["Path"]
| @"\\ServerPath\SharedFolder"
I've also tried with this format: \\ServerPath\SharedFolder... None of them worked.
By the way its not an access problem, cause i've tried to do the same thing running a command prompt from within c#:
System.Diagnostics.Process.Start("cmd.exe", "/C COPY PATH1, PATH2"); //This worked and copied the file.
I'd be greatful if someone could give me a clue of what could be the problem here. At least an advice of what to do.
Thanks in advance and sorry me bad english!
Edit:
This is the part of the code that should work:
string pathPrevDay = "D:\AuditFiles\enc_" + svr.Name + "_counts" + day.AddDays(-1).ToString("dd-MM-yy") + ".txt";
if(File.Exists(pathPrevDay))
{
File.Copy(pathPrevDay, @ConfigurationManager.AppSettings["MAIL_SERVER_PATH"]);
}
解决方案
You need to escape the backslashes and indicate the name of the file in File.Copy(pathPrevDay, ConfigurationManager.AppSettings["MAIL_SERVER_PATH"]);.
Change this:
string pathPrevDay = "D:\AuditFiles\enc_" + svr.Name + "_counts" + day.AddDays(-1).ToString("dd-MM-yy") + ".txt";
to this:
string pathPrevDay = "D:\\AuditFiles\\enc_" + svr.Name + "_counts" + day.AddDays(-1).ToString("dd-MM-yy") + ".txt";
You can also use single slashes (/) instead like this:
string pathPrevDay = "D:/AuditFiles/enc_" + svr.Name + "_counts" + day.AddDays(-1).ToString("dd-MM-yy") + ".txt";
上一篇:如何使自定义DataGridViewComboBox只依赖于它的DataGridViewComboBoxColumn?它的、自定义、依赖于、DataGridViewComboBoxColumn