特定のファイルのフルパスを取得するにはどうすればよいですか?
たとえば、私は提供します:
string filename = @"test.txt";
結果は次のようになります。
Full File Path = C:\Windows\ABC\Test\test.txt
試す
string fileName = "test.txt";
FileInfo f = new FileInfo(fileName);
string fullname = f.FullName;
Path.GetFullPath() を使用します。
http://msdn.microsoft.com/en-us/library/system.io.path.getfullpath.aspx
これにより、完全なパス情報が返されます。
あなたが使用することができます:
string path = Path.GetFullPath(FileName);
その言及されたファイルのフルパスを返します。
string dirpath = Directory.GetCurrentDirectory();
Prepend this dirpath to the filename to get the complete path.
As @Dan Puzey indicated in the comments, it would be better to use Path.Combine
Path.Combine(Directory.GetCurrentDirectory(), filename)
私は自分の答えが遅すぎることを知っていますが、それは他の人に役立つかもしれませ
ん
Void Main()
{
string filename = @"test.txt";
string filePath= AppDomain.CurrentDomain.BaseDirectory + filename ;
Console.WriteLine(filePath);
}
try..
Server.MapPath(FileUpload1.FileName);
試す:
string fileName = @"test.txt";
string currentDirectory = Directory.GetCurrentDirectory();
string[] fullFilePath = Directory.GetFiles(currentDirectory, filename, SearchOption.AllDirectories);
現在のディレクトリとそのサブディレクトリにあるそのようなすべてのファイルのフル パスを文字列配列 fullFilePath に返します。ファイルが 1 つしか存在しない場合は、「fullFileName[0]」になります。
private const string BulkSetPriceFile = "test.txt";
...
var fullname = Path.GetFullPath(BulkSetPriceFile);
現在のパスを取得できます。
string AssemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString();
幸運を!