none
Opening a folder from C#

    Question

  • Is there a way to open a folder (the physical folder opening up on your screen. For example "My Documents") on the fly in C#? I have been searching all over the web for a while now and have come up dry. Any help would be great.
    Friday, August 26, 2005 6:31 PM

Answers

  • Could you be more precise about "open"?
    If you want to open it with explorer try this code:




    string myDocspath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    string windir = Environment.GetEnvironmentVariable("WINDIR");
    System.Diagnostics.
    Process prc = new System.Diagnostics.Process();
    prc.StartInfo.FileName = windir +
    @"\explorer.exe";
    prc.StartInfo.Arguments = myDocspath;
    prc.Start();


     


    If you just want to "open" it in a variable (in other words, assign it) just use the first line of my code!

    Thanx!
    Friday, August 26, 2005 8:09 PM

All replies

  • Could you be more precise about "open"?
    If you want to open it with explorer try this code:




    string myDocspath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    string windir = Environment.GetEnvironmentVariable("WINDIR");
    System.Diagnostics.
    Process prc = new System.Diagnostics.Process();
    prc.StartInfo.FileName = windir +
    @"\explorer.exe";
    prc.StartInfo.Arguments = myDocspath;
    prc.Start();


     


    If you just want to "open" it in a variable (in other words, assign it) just use the first line of my code!

    Thanx!
    Friday, August 26, 2005 8:09 PM
  • This was very helpful! thank you!

    How can i open  any other folder; for example "C:\Users\admin\Desktop\fotos" 

    thanks in advance...

    Sunday, March 21, 2010 2:09 PM
  • You don't need to explicitly call explorer.exe. Just put the folder path in the FileName.

    string myPath = @"C:\Users\admin\Desktop\fotos";
    System.Diagnostics.Process prc = new System.Diagnostics.Process();
    prc.StartInfo.FileName = myPath;
    prc.Start();

    Sunday, March 21, 2010 10:27 PM
  • Hi, how can I open a folder for example D:\X and select a FILE in it, a file D:\X\y.jpg  (as an example). 

    Thanks

    Thursday, June 23, 2011 6:26 PM
  • Thnx a lot !!!
    Friday, August 26, 2011 8:42 PM
  • This code works fine from the VS2010 environment and opens the local folder properly, but if you host same the application in IIS and try to open then it will fail for sure.



    Software Engineer

    Tuesday, July 08, 2014 8:37 AM