System.ArgumentException:路径中的非法字符.错误 [英] System.ArgumentException: Illegal characters in path. error

查看:535
本文介绍了System.ArgumentException:路径中的非法字符.错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从以下代码获取ArgumentException:

I`m getting an ArgumentException from the following code:

string strPath="C:\somename.xls";
startPath=System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
filePath = System.IO.Path.Combine(startPath, strPath);

我在堆栈溢出中找到了此代码. 关联: C#:将受保护的工作表复制到另一个Excel文件 我不知道这是什么.请告诉我这是什么.我正在将这个代码构建到exe中.

I found this code on Stack Overflow. Link: C#:Copy protected worksheet to another excel file I don't exactly know what it is. Please tell me what it is. This code I'm building into an exe.

最后,我需要将一个工作表复制到另一个文件.

Lastly, I need to Copy one worksheet to another file.

我在做什么错?我将其部署在服务器中.

What`s wrong am I doing? I deploy this in server.

推荐答案

该代码似乎在做什么,它是否获取您的工作目录(与代码关联的exe所在的位置),并将其与"C:\\somename.xls"组合(这没有任何意义.)

what that code appears to do, is it gets your working directory(wherever the exe associated with your code is), and combines it with "C:\\somename.xls"(which doesn't make sense.)

我认为您可能打算这样做

I think you might have intended something like

string strPath=@"somename.xls";

所以假设您正在从

"C:\Users\owner\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug"

将代码执行的操作设置为filePath

what that code would do is set filePath to

"C:\Users\owner\documents\visual studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\bin\Debug\somename.xls"


我看到的第一件事是


the first thing I saw was

string filePath="C:\somename.xls";

\是特殊字符,用于确定其他字符.例如'\n'是换行符. '\\'是实际的反斜杠.

\ is a special character, for determining other characters. for instance '\n' is a newline. '\\' is the actual backslash.

所以,您想用另一个\

string filePath="C:\\somename.xls";

或在其前面放置@使其成为文字字符串.

or make it a literal string by putting a @ in front of it.

string filePath=@"C:\somename.xls";

这篇关于System.ArgumentException:路径中的非法字符.错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆