When searching a file in Windows Explorer and right-click a file from the search results; there is an option: “Open file location”. I want to implement the same in my C# WinForm. I did this:
if (File.Exists(filePath)
{
openFileDialog1.InitialDirectory = new FileInfo(filePath).DirectoryName;
openFileDialog1.ShowDialog();
}
Is there any better way to do it?
If
openFileDialog_Viewis an OpenFileDialog then you’ll just get a dialog prompting a user to open a file. I assume you want to actually open the location in explorer.You would do this:
To select a file
explorer.exetakes a/selectargument like this:I got this from an SO post: Opening a folder in explorer and selecting a file
So your code would be: