Search:
Welcome Guest | Register | Login
logo

Get Directory name from full path of file?

I am new to C#, please help me to get the directory name from full path of a file, say

D:\Projects\ProjectName\CarDocuments\CarBook.pdf
  • ASP.Net
  • C#
1
 
Asked: 02 Mar 2013
Reputation: 95
Rodrigo Serna
2 Answers

use .DirectoryInfo(path).Name to get the directory Name

String dirName = new System.IO.DirectoryInfo(path).Name;
0
 
Answered: 04 Mar 2013
Reputation: 242
Jonathan King

Check this by using FileInfo

FileInfo fileInfo = new FileInfo(path);
String dirName = fileInfo.Diretory.Name;
0
 
Answered: 04 Mar 2013
Reputation: 296
Jason Olivera
Login to post your answer