Tuesday, September 21, 2004
System.IO.FileSystemInfo
This is nothing new, but I felt the need to share since so many miss it.
Many a times I see stuff like this being done (even I also did for sometime):
string FolderPath = FilePath.Substring(0, FilePath.LastIndexOf(@"\"));
Obviously they are trying to get the full path to a file. Next time your thinking about doing something like that consider:
System.IO.FileInfo fi = new System.IO.FileInfo(FilePath);
string FolderPath = fi.DirectoryName;
Much easier.
Take a look at all the other goodies in the System.IO.FileInfo class:
fi.Extension
fi.FullName
fi.Name
fi.Length
fi.Directory.FullName
fi.Directory.Name
fi.Directory.Root.FullName
fi.DirectoryName
Not to mention these methods:
fi.Open();
fi.OpenRead();
fi.OpenText();
fi.OpenWrite();
More: http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemIOFileInfoClassTopic.asp
With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/
Many a times I see stuff like this being done (even I also did for sometime):
string FolderPath = FilePath.Substring(0, FilePath.LastIndexOf(@"\"));
Obviously they are trying to get the full path to a file. Next time your thinking about doing something like that consider:
System.IO.FileInfo fi = new System.IO.FileInfo(FilePath);
string FolderPath = fi.DirectoryName;
Much easier.
Take a look at all the other goodies in the System.IO.FileInfo class:
fi.Extension
fi.FullName
fi.Name
fi.Length
fi.Directory.FullName
fi.Directory.Name
fi.Directory.Root.FullName
fi.DirectoryName
Not to mention these methods:
fi.Open();
fi.OpenRead();
fi.OpenText();
fi.OpenWrite();
More: http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemIOFileInfoClassTopic.asp
With Best Regards,
Mitesh Mehta
Email : miteshvmehta@gmail.com
http://cc.1asphost.com/miteshvmehta/