try:
string fileName = @"test.txt";
string currentDirectory = Directory.GetCurrentDirectory();
string[] fullFilePath = Directory.GetFiles(currentDirectory, filename, SearchOption.AllDirectories);
it will return full path of all such files in the current directory and its sub directories to string array fullFilePath. If only one file exist it will be in "fullFileName[0]".
private const string BulkSetPriceFile = "test.txt";
...
var fullname = Path.GetFullPath(BulkSetPriceFile);
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)
Try
string fileName = "test.txt";
FileInfo f = new FileInfo(fileName);
string fullname = f.FullName;
try..
Server.MapPath(FileUpload1.FileName);
You Can use:
string path = Path.GetFullPath(FileName);
it will return the Full path of that mentioned file.
Use Path.GetFullPath():
http://msdn.microsoft.com/en-us/library/system.io.path.getfullpath.aspx
This should return the full path information.
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);
}
You can get the current path:
string AssemblyPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString();
Good luck!
Source: Stackoverflow.com