Showing document in Windows Explorer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • z1freeride
    New Member
    • Feb 2009
    • 36

    Showing document in Windows Explorer

    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:

    Code:
    Process proc = new Process();
    proc.StartInfo.FileName = "explorer.exe";
    proc.StartInfo.Arguments = dlPath;
    proc.Start();
    This simply opens the folder but in Firefox, it hilights the file. How would I do that?
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Here's what I would do:
    Code:
    //change this line to whatever path you have:
    string filepath = @"c:\dev\pointredemption.txt";
    FileInfo fi = new FileInfo(filepath);
    if (fi.Exists)
    {
        Process proc = new Process();
        proc.StartInfo.FileName = "explorer.exe";
        proc.StartInfo.Arguments = "/select," + filepath; ;
        proc.Start();
    }
    else
        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

    Comment

    • z1freeride
      New Member
      • Feb 2009
      • 36

      #3
      Perfect. Thank you!

      20 characters....

      Comment

      Working...