使用C#获取解决方案文件的父文件夹的路径 [英] Getting path to the parent folder of the solution file using C#
本文介绍了使用C#获取解决方案文件的父文件夹的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是C#的初学者,并且有一个我要从中读取文件的文件夹.
I am a beginner in C#, and I have a folder from which I am reading a file.
我想读取一个文件,该文件位于解决方案文件的父文件夹中.我该怎么做?
I want to read a file which is located at the parent folder of the solution file. How do I do this?
string path = "";
StreamReader sr = new StreamReader(path);
因此,如果我的文件XXX.sln
位于C:\X0\A\XXX\
中,则读取C:\X0\A\
中的.txt
文件.
So if my file XXX.sln
is in C:\X0\A\XXX\
then read the .txt
files in C:\X0\A\
.
推荐答案
尝试一下:
string startupPath = Path.Combine(Directory.GetParent(System.IO.Directory.GetCurrentDirectory()).Parent.Parent.Parent.FullName,"abc.txt");
// Read the file as one string.
string text = System.IO.File.ReadAllText(startupPath);
这篇关于使用C#获取解决方案文件的父文件夹的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文