How do I get the full path for a given file?
e.g. I provide:
string filename = @"test.txt";
Result should be:
Full File Path = C:\Windows\ABC\Test\test.txt
Click the Start button and then click Computer, click to open the location of the desired file, hold down the Shift key and right-click the file. Copy As Path: Click this option to paste the full file path into a document. Properties: Click this option to immediately view the full file path (location).
To extract filename from the file, we use “GetFileName()” method of “Path” class. This method is used to get the file name and extension of the specified path string. The returned value is null if the file path is null. Syntax: public static string GetFileName (string path);
The full path means the address at which the file is located. This includes all the directories and subdirectories. For example, We have a file named file1. txt. Its complete address will be /home/sid/Desktop/test/file1.
Paths include the root, the filename, or both. That is, paths can be formed by adding either the root, filename, or both, to a directory.
You Can use:
string path = Path.GetFullPath(FileName);
it will return the Full path of that mentioned file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With