Saving / Resetting current directory

  • Thread starter Thread starter Tim Kelley
  • Start date Start date
T

Tim Kelley

I have a project that includes images as part of the project. I have a grid
(Infragistics) with a button that the user clicks and it brings up a file
open dialog that is used to browse to a file so the path can be saved in the
grid. After the dialog is closed the program cannot find any of the images
that are part of the project. I believe that using the open file dialog is
changing the working directory and causing the error. Is there a way to
save the working directory, do the open file dialog and then reset the
working directory to its original state?
 
To get the current path where the program is being run from, use
the static CurrentDirectory property on the Environment class. You can also
save the path into a static string field after the user saves the image. This
can then be used later when the OpenFileDialog is invoked again.
 
[...] I believe that using the open file dialog is
changing the working directory and causing the error. Is there a way to
save the working directory, do the open file dialog and then reset the
working directory to its original state?

Yes. Set the RestoreDirectory property to "true" before calling
ShowDialog().

There are other ways to solve the problem, but it seems to me that's the
simplest.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top