C\#현재 디 렉 터 리 에서 이전 디 렉 터 리 를 찾 을 수 있 습 니 다.
/// <summary>
///
/// </summary>
/// <returns></returns>
public string GetProjectRootPath()
{
string rootPath = "";
string BaseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory; // F:\project\WPF\AstroATE-PDR\04. \01. \AstroATE\AstroATE\bin\Debug
// ,
rootPath = BaseDirectoryPath.Substring(0, BaseDirectoryPath.LastIndexOf("\\")); // \ ,
rootPath = rootPath.Substring(0, rootPath.LastIndexOf(@"\")); //
rootPath = rootPath.Substring(0, rootPath.LastIndexOf("\\")); // @"F:\project\WPF\AstroATE-PDR\04. \01. \AstroATE\AstroATE
return rootPath;
}
이 함수 호출:
string str = GetProjectRootPath() + @"\data\ .pdf"; //
자,이렇게 하면 해결 된다.추가:C\#실행 가능 한 파일 경로 의 상위 디 렉 터 리 를 가 져 오 는 방법
첫 번 째 종류:
DirectoryInfo di = new DirectoryInfo(string.Format(@"{0}..\..\", Application.StartupPath));
di.FullName
몇 개 는 몇 층 으로 되 돌아 가 는 거 예요.두 번 째:
DirectoryInfo info = new DirectoryInfo(Application.StartupPath);
String path = info.Parent.Parent.FullName;
세 번 째:
string WantedPath = Application.StartupPath.Substring(0,Application.StartupPath.LastIndexOf(@"\"));
이상 은 개인 적 인 경험 이 므 로 여러분 에 게 참고 가 되 기 를 바 랍 니 다.여러분 들 도 저 희 를 많이 응원 해 주시 기 바 랍 니 다.만약 잘못 이 있 거나 완전히 고려 하지 않 은 부분 이 있다 면 아낌없이 가르침 을 주시 기 바 랍 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
WebView2를 Visual Studio 2017 Express에서 사용할 수 있을 때까지Evergreen .Net Framework SDK 4.8 VisualStudio2017에서 NuGet을 사용하기 때문에 패키지 관리 방법을 packages.config 대신 PackageReference를 사용해야...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.