C#导航到startupPath的其他文件夹

C#导航到startupPath的其他文件夹,c#,wpf,path,C#,Wpf,Path,我在解决方案中添加了一个可执行文件,我想替换System.Windows.Forms.Application.StartupPath到可执行文件位置。不幸的是,它会继续导航到Bin\debug文件夹,我不想这样,我需要再上一层 string pintoolpath = System.Windows.Forms.Application.StartupPath.Replace(@"\bin\Debug", "").Replace(@"\bin\Release", ""); 我就是这么做的,但是当我

我在解决方案中添加了一个可执行文件,我想替换System.Windows.Forms.Application.StartupPath到可执行文件位置。不幸的是,它会继续导航到Bin\debug文件夹,我不想这样,我需要再上一层

string pintoolpath = System.Windows.Forms.Application.StartupPath.Replace(@"\bin\Debug", "").Replace(@"\bin\Release", "");
我就是这么做的,但是当我把它打印到一个消息框中时,它实际上并没有取代它。我如何导航到另一个文件夹

仅供参考:使用..\向上导航当前不起作用,如下所示:

string pintoolpath = System.Windows.Forms.Application.StartupPath.Replace(@"..\\bin\Debug", "").Replace(@"..\\bin\Release", "");

我已经找到了答案

解决方案资源管理器上的直接路径具有与实际路径不同的字符。例如,Bin中的B在实际路径中大写,而解决方案资源管理器将其作为小写。一旦更改了这些,我就能够通过导航到适当的文件夹来获得正确的路径

string pintoolpath = System.Windows.Forms.Application.StartupPath.Replace(@"\Bin\debug", "").Replace(@"\Bin\release", "")

谢谢拉胡尔帮助我

System.Windows.Forms.Application.StartupPath默认为可执行文件路径。对于您试图实现的目标,一种方法是将启动路径保存在一个临时字符串变量中,如'string StartupPath=System.Windows.Forms.Application.StartupPath;'然后将其内容替换为“string pintoolpath=StartupPath.replace”(“bin\\Debug”,“bin\\Release”)”有趣的注释-但这是我必须替换的示例:string pintoolpath=System.Windows.Forms.Application.StartupPath.replace(@“\bin\Debug“,”).replace(@“\bin\Release“,”)+@“\Notepad\Notepad.exe”;但是由于某些原因,文件夹结构实际上没有导航到记事本文件夹并在记事本上执行(仅供参考,以该文件夹为例),那么为什么要使用启动路径呢。只需给出您自己的位置,如'string pintoolpath=“D:\\AbcFolder\\XyzFolder\\Notepad\\Notepad.exe'。只需使用双反斜杠\\提及您的文件/文件夹路径,因为我已在解决方案资源管理器中添加了可执行文件,任何下载该工具的人都需要访问它。尽管我没有以更好的方式帮助您,但很好,你自己解决了:)