简体   繁体   中英

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. But I'm throwing an UnsupportedFormatException on the path when it tries to use Directory.GetFiles(path) .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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