1

asp.net Web アプリがあり、Web アプリと同じディレクトリにあるフォルダーの文字列パスを取得する必要があります。現在、このコードを使用して追加ドメインパスを取得しています。

string appPath = HttpRuntime.AppDomainAppPath;

これは「c:/path/webapp」を返します。「c:/path/folder」が必要です。

ありがとう。

4

2 に答える 2

2

開始フォルダーを知る必要のない、より一般的なアプローチが必要な場合は、次のようにします。

//NOTE:  using System.IO;
String startPath = Path.GetDirectoryName(HttpRuntime.AppDomainAppPath);
Int32 pos = startPath.LastIndexOf(Path.DirectorySeparatorChar);
String newPath = Path.Combine(startPath.Substring(0, pos), "folder");  //replace "folder" if it's really something else, of course

このようにして、Web アプリが実行されているディレクトリが何であれ、それを取得し、それを 1 レベル減らし、「フォルダー」を追加して新しい兄弟ディレクトリを取得できます。

于 2013-05-31T10:48:22.337 に答える