Connecting Tech Pros Worldwide Forums | Help | Site Map

Showing document in Windows Explorer

Member
 
Join Date: Feb 2009
Posts: 35
#1: Jul 1 '09
I'm programming a download manager and I'm trying to implement the "Show Containing Folder" feature that you would find in Firefox.

This is what I have so far:

Expand|Select|Wrap|Line Numbers
  1. Process proc = new Process();
  2. proc.StartInfo.FileName = "explorer.exe";
  3. proc.StartInfo.Arguments = dlPath;
  4. proc.Start();
This simply opens the folder but in Firefox, it hilights the file. How would I do that?

insertAlias's Avatar
Forum Leader
 
Join Date: Apr 2008
Location: San Antonio, TX (USA)
Posts: 2,608
#2: Jul 1 '09

re: Showing document in Windows Explorer


Here's what I would do:
Expand|Select|Wrap|Line Numbers
  1. //change this line to whatever path you have:
  2. string filepath = @"c:\dev\pointredemption.txt";
  3. FileInfo fi = new FileInfo(filepath);
  4. if (fi.Exists)
  5. {
  6.     Process proc = new Process();
  7.     proc.StartInfo.FileName = "explorer.exe";
  8.     proc.StartInfo.Arguments = "/select," + filepath; ;
  9.     proc.Start();
  10. }
  11. else
  12.     Console.WriteLine("DNE!");
Make sure to include using System.IO; to use the FileInfo object.

Basically, this will check to see if the file exists. If it does, it will start explorer and highlight the file. Otherwise, it will write to the console, but you can change that part.

Hope this helps.

Source: http://support.microsoft.com/kb/314853
Member
 
Join Date: Feb 2009
Posts: 35
#3: Jul 1 '09

re: Showing document in Windows Explorer


Perfect. Thank you!

20 characters....
Reply

Tags
folder, show