如何从 ConfigurationManager.AppSetting[“settingname”].ToString() 返回逐字字符串
我正在使用 ConfigurationManager.AppSetting["blah"].ToString()
方法来获取包含我需要的文件的文件夹的路径。但是当它尝试使用 Directory.GetFiles(path)
时,我在路径上抛出 UnsupportedFormatException
。
返回值包含转义字符,我不确定如何阻止它返回额外的字符。返回后路径如下所示:
\\\\\\\\C:\\\\folder1\\\\folder2
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我需要删除前四个“\”才能给它一个正确的路径。
I needed to remove the first four "\" to give it a correct path.
您的路径开头有额外的反斜杠
\
。尝试在配置文件中放入“C:\folder1\folder2”而不是“\\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.