Below is a technique that uses FolderNameEditor and FolderBrowser classes to implement a solution. You can also use iterop to get a solution.
Both the FolderNameEditor and FolderBrowser classes used in this solution are described in the Docs as ‘This type supports the .NET Framework infrastructure and is not intended to be used directly from your code.’
// add a reference to System.Design.DLLusing System.Windows.Forms.Design;
.............
publicclassDirBrowser : FolderNameEditor
{
FolderBrowser fb = new FolderBrowser();
publicstring Description
{
set { _description = value; }
get { return _description; }
}
publicstring ReturnPath
{
get { return _returnPath; }
}
publicDirBrowser() { }
public DialogResult ShowDialog()
{
fb.Description = _description;
fb.StartLocation = FolderBrowserFolder.MyComputer;
DialogResult r = fb.ShowDialog();
if (r == DialogResult.OK)
_returnPath = fb.DirectoryPath;
else
_returnPath = String.Empty;
return r;
}
privatestring _description = 'Choose Directory';
privatestring _returnPath = String.Empty;
}
(Posted by Ryan Farley on the microsoft.public.dotnet.language.csharp newsgroup)
Use FileInfo. Instantiate a FileInfo object with the full path as constructor arg. Then simply call FileInfo.Extension and you will get just the extension of the file.
FileInfo finfo = new FileInfo(strFileName);
Console.WriteLine(finfo.Extension);
Use FileInfo. Instantiate a FileInfo object with the full path as constructor arg. Then simply call FileInfo.Name and you will get just the name of the file.
FileInfo finfo = new FileInfo(strFileName);
Console.WriteLine(finfo.Name);