简体   繁体   English

如何从ConfigurationManager.AppSetting [“ settingname”]。ToString()返回一个逐字字符串

[英]How to return a verbatim string from ConfigurationManager.AppSetting[“settingname”].ToString()

I am using the ConfigurationManager.AppSetting["blah"].ToString() method to get the path to the folder that contains the files I'm needing. 我正在使用ConfigurationManager.AppSetting["blah"].ToString()方法来获取包含我所需文件的文件夹的路径。 But I'm throwing an UnsupportedFormatException on the path when it tries to use Directory.GetFiles(path) . 但是,当它尝试使用Directory.GetFiles(path)时,我在路径上抛出了UnsupportedFormatException

The returning value has the escape characters included and I'm not sure how to keep it from returning the extra characters. 返回值包含转义字符,我不确定如何防止它返回多余的字符。 This is what the path looks like after it is returned: 这是返回路径后的样子:

\\\\\\\\\\\\\\\\C:\\\\\\\\folder1\\\\\\\\folder2

我需要删除前四个“ \\”以提供正确的路径。

you have extra back-slash \\ at the beginning of your path. 您在路径的开头有多余的反斜杠\\

try putting "C:\\folder1\\folder2" instead of "\\\\C:\\folder1\\folder2" in your config file, and it will work. 尝试在配置文件中放入“ C:\\ folder1 \\ folder2”而不是“ \\\\ C:\\ folder1 \\ folder2”,它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM