1

マシンの E ドライブに「DbInventory」というディレクトリ名を作成しました。C# アプリケーションで、このディレクトリ (DbInventory) のフル パスを取得したいと考えています。

以下は、私が使用したコードについて言及しています

DirectoryInfo info = new DirectoryInfo("DbInventory");
string currentDirectoryName = info.FullName;

しかし、この currentDirectoryName 文字列は、C ドライブのファイルの場所を返します。

4

4 に答える 4

1

で作成しています

new DirectoryInfo("DbInventory");

デフォルト ドライブ (C) の新しいディレクトリ。見てみましょう: MSDN

ドライブ E に既に作成されているディレクトリ情報オブジェクトを取得する場合は、パスを指定する必要があります。

于 2013-07-18T06:36:05.587 に答える
1

Path.GetDirectoryNameを使用できます

DirectoryInfo info = new DirectoryInfo("DbInventory");
string currentDirectoryName = info.FullName;
string directoryPath = Path.GetDirectoryName(path);
于 2013-07-18T06:36:29.123 に答える
0

server.mappath を試す

string currentDirectoryName =Server.MapPath(info.FullName);

これがうまくいくことを願っています

于 2013-07-18T06:36:03.090 に答える