Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

C# Simply want to open a folder given the path

Posted on 2007-10-11
6
Medium Priority
?
2,354 Views
Last Modified: 2008-01-09
I seem to be able to check files in a folder and have a user navigate to a folder but what code can I use to open the folder for the user (i.e. C:\temp\stuff\).

Thanks!
Karl66
0
Comment
Question by:Karl66
  • 3
  • 3
6 Comments
 
LVL 7

Accepted Solution

by:
bungHoc earned 750 total points
ID: 20057129
To Open a folder in Explorer, just:
System.Diagnostics.Process.Start(@"explorer.exe", @"C:\Windows");

Or this:
System.Diagnostics.Process.Start(@"C:\Windows");

Since Explorer is the asscoaited handler for folder.


0
 

Author Comment

by:Karl66
ID: 20057259
Is there a way to have it open the last opened directory rather than have to provide a path?
0
 
LVL 7

Expert Comment

by:bungHoc
ID: 20057357
This should do the trick
{
  FileSystemWatcher watcher = new FileSystemWatcher();
  watcher.Path = "";

  watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;

  // Add event handlers.
  watcher.Changed += new FileSystemEventHandler(OnChanged);
}

private static void OnChanged(object source, FileSystemEventArgs e)
{
        // Specify what is done when a file is changed, created, or deleted.
       string newPath = e.FullPath;
}
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Karl66
ID: 20057611
Give that code where would I put:

System.Diagnostics.Process.Start(@"C:\Windows");

and what would I change (@"C:\Windows) to?
0
 
LVL 7

Expert Comment

by:bungHoc
ID: 20058029
Geez.. just replace that with:
string path = "some path";
0
 

Author Comment

by:Karl66
ID: 20058148
write but I meant in the longer code. Whe I run it it displays nothing so I assume it needs the System line somewhere...

{
  FileSystemWatcher watcher = new FileSystemWatcher();
  watcher.Path = "";

  watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;

  // Add event handlers.
  watcher.Changed += new FileSystemEventHandler(OnChanged);
}

private static void OnChanged(object source, FileSystemEventArgs e)
{
        // Specify what is done when a file is changed, created, or deleted.
       string newPath = e.FullPath;
}
back to top
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question