Get Full Path of a File
The FullName property returns just the full path of a file including the file name. The following code snippet returns the full path of a file.
- string fullFileName = fi.FullName;
- Console.WriteLine("File Name: {0}", fullFileName);
Sample
Here is a complete sample.
-
- string fileName = @"/Users/praveen/Desktop/images\November.pdf";
- FileInfo fi = new FileInfo(fileName);
-
-
- using (FileStream fs = fi.Create())
- {
- Byte[] txt = new UTF8Encoding(true).GetBytes("New file.");
- fs.Write(txt, 0, txt.Length);
- Byte[] author = new UTF8Encoding(true).GetBytes("Author Mahesh Chand");
- fs.Write(author, 0, author.Length);
- }
-
-
- string justFileName = fi.Name;
- Console.WriteLine("File Name: {0}", justFileName);
-
- string fullFileName = fi.FullName;
- Console.WriteLine("File Name: {0}", fullFileName);
-
- string extn = fi.Extension;
- Console.WriteLine("File Extension: {0}", extn);
-
- string directoryName = fi.DirectoryName;
- Console.WriteLine("Directory Name: {0}", directoryName);
-
- bool exists = fi.Exists;
- Console.WriteLine("File Exists: {0}", exists);
- if (fi.Exists)
- {
-
- long size = fi.Length;
- Console.WriteLine("File Size in Bytes: {0}", size);
-
- bool IsReadOnly = fi.IsReadOnly;
- Console.WriteLine("Is ReadOnly: {0}", IsReadOnly);
-
- DateTime creationTime = fi.CreationTime;
- Console.WriteLine("Creation time: {0}", creationTime);
- DateTime accessTime = fi.LastAccessTime;
- Console.WriteLine("Last access time: {0}", accessTime);
- DateTime updatedTime = fi.LastWriteTime;
- Console.WriteLine("Last write time: {0}", updatedTime);
- }