私の Web プロジェクト ソリューションには、多数のプロジェクトが追加されています。
プロジェクトの1つに「Localization」というフォルダー名があります。
したがって、別のプロジェクトのコード ビハインドでフォルダー名を指定して、フォルダーの完全なパスを取得するにはどうすればよいですか。
プロジェクトの 1 つにフォルダーが存在する場合は、完全なパスを取得する必要があります。
「フォルダーが存在する場合」と述べているため、最初にフォルダーが存在するかどうかをテストする必要があります。
DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/FolderName"));
if (dir.Exists)
{
//dir.FullName will get you the path.
//This is the same things as Server.MapPath("~/FolderName"), but that
//will return a path even if the folder isn't there.
}
else
{
//folder doesn't exist.
}
プロジェクトの外に出ようとしているので、次のようなことができます (ソリューションの構造によって異なります)。
string path = Path.GetFullPath(Path.Combine(Server.MapPath("~"), @"..\OtherProjectName/FolderName"));
DirectoryInfo dir = new DirectoryInfo(path);
この例を使用して、別のフォルダーの完全なパスを取得できます。
System.IO.Path.GetFullPath(System.IO.Path.Combine(Server.MapPath("~"), "../Localization/"));