var storePath = ConfigurationManager.AppSettings[configKey];
var dbpath=dbpath.replace("/","\\")
var fullFilePath = Path.Combine(storePath, dbpath);
存储在配置密钥中的值 - > d:\Storage\ResourceStorage
值: dbpath:LearnerAnswers\test.pkg
预期输出: d:\Storage\ResourceStorage\LearnerAnswers\test.pkg
实际输出: D:\LearnerAnswers\test.pkg
更新了问题以反映具体情况
来自商店路径调试器的 值: d:\Storage\ResourceStorage
我花了很多时间在这上面......但是找不到什么问题?
答案 0 :(得分:0)
我已经检查了你在问题中提供的示例路径,我得到了完全预期的输出。
var storePath = @"d:\Storage\ResourceStorage";
var dbpath = @"LearnerAnswers\test.pkg";
var fullFilePath = Path.Combine(storePath, dbpath);
必须有别的东西是错的。请在单步模式下使用调试器并验证每个值。
以下原始答案是由于问题中首先提供的信息无效。
您需要在此处引用反斜杠或使用 @
:
var storePath = "d:\Storage\ResourceStorage";
请使用以下其中一项:
var storePath = @"d:\Storage\ResourceStorage";
var storePath = "d:\\Storage\\ResourceStorage";
击> <击> 撞击>
答案 1 :(得分:0)
DBPath
是否以"\\"
开头?
Path.Combine
假设您的第二个变量以"\\"
或@"\"
Path.Combine("C:\\test", "\\NewFolder")
返回"c:\\NewFolder"
Path.Combine("C:\\test", "NewFolder")
返回"c:\\test\\NewFolder"