How do I get the full path for a given file?
e.g. I provide:
string filename = @\"test.txt\";
Result should be:
Full Fi
Try
string fileName = "test.txt";
FileInfo f = new FileInfo(fileName);
string fullname = f.FullName;
Directory.GetCurrentDirectory
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)
You Can use:
string path = Path.GetFullPath(FileName);
it will return the Full path of that mentioned file.
private const string BulkSetPriceFile = "test.txt";
...
var fullname = Path.GetFullPath(BulkSetPriceFile);
I know my answer it's too late, but it might helpful to other's
Try,
Void Main()
{
string filename = @"test.txt";
string filePath= AppDomain.CurrentDomain.BaseDirectory + filename ;
Console.WriteLine(filePath);
}
Use Path.GetFullPath():
http://msdn.microsoft.com/en-us/library/system.io.path.getfullpath.aspx
This should return the full path information.