【发布时间】:2013-04-02 16:10:31
【问题描述】:
如何向控制台应用程序提供自动转义的输入字符串?
我的意思是在我的代码中,我可以做到
public static void main(string[] args)
{
string myURL;
myFolder = @"C:\temp\january\"; //just for testing
myFolder = args[0]; // I want to do this eventually
}
如何为 myFolder 提供值而无需通过命令行手动对其进行转义?
如果可能的话,我想避免这样调用这个应用程序:
C:\test> myapplication.exe "C:\\temp\\january\\"
编辑: 相反,如果可能的话,我更喜欢这样调用应用程序
C:\test> myapplication.exe @"C:\temp\january\"
谢谢。
编辑:
这实际上是用于调用 Sharepoint Web 服务的控制台应用程序。我试过了
string SourceFileFullPath, SourceFileName, DestinationFolder, DestinationFullPath;
//This part didn't work. Got Microsoft.SharePoint.SoapServer.SoapServerException
//SourceFileFullPath = args[0]; // C:\temp\xyz.pdf
//SourceFileName = args[1]; // xyz.pdf
//DestinationFolder = args[2]; // "http://myserver/ClientX/Performance" Reports
//This worked.
SourceFileFullPath = @"C:\temp\TestDoc2.txt";
SourceFileName = @"TestDoc2.txt";
DestinationFolder = @"http://myserver/ClientX/Performance Reports";
DestinationFullPath = string.Format("{0}/{1}", DestinationFolder, SourceFileName);
【问题讨论】:
-
您已说明如何不想调用该应用程序。您究竟想如何调用该应用程序?
-
你为什么要在命令行中 c#-escape 输入?这没有任何意义——命令行不是 c#
-
也许如果你尝试传递你的论点,你会发现没有必要逃避任何事情
-
@Steve 请看我的更新。
标签: c# command-line-arguments verbatim-string