Home All Groups Group Topic Archive Search About

initial directory of openfiledialog

Author
7 Apr 2005 2:44 PM
Eps
I have a problem that is driving me crazy, I have and openfiledialog but
I can't seem to set its initial path.

I have the  initalDirecotry property set to the correct path but it
always opens at the last directory I opened a file in.

Does anyone have any idea how I can fix this ?.

Also is there any way to get the current path from where a program is
being run from ?

Any help appreciated.

--
Eps

Author
7 Apr 2005 2:52 PM
Nicholas Paldino [.NET/C# MVP]
Eps,

    Are you using the same instance for each time, or are you using a
different instance of the OpenFileDialog each time?

    Also, to get the current path where the program is being run from, use
the static CurrentDirectory property on the Environment class.

    Hope this helps.


--
               - Nicholas Paldino [.NET/C# MVP]
               - mvp@spam.guard.caspershouse.com

Show quoteHide quote
"Eps" <e**@mailinator.com> wrote in message
news:d33h0o$eb9$1@domitilla.aioe.org...
>I have a problem that is driving me crazy, I have and openfiledialog but I
>can't seem to set its initial path.
>
> I have the  initalDirecotry property set to the correct path but it always
> opens at the last directory I opened a file in.
>
> Does anyone have any idea how I can fix this ?.
>
> Also is there any way to get the current path from where a program is
> being run from ?
>
> Any help appreciated.
>
> --
> Eps
Are all your drivers up to date? click for free checkup

Author
7 Apr 2005 3:44 PM
Eps
Nicholas Paldino [.NET/C# MVP] wrote:
> Eps,
>
>     Are you using the same instance for each time, or are you using a
> different instance of the OpenFileDialog each time?
>
>     Also, to get the current path where the program is being run from, use
> the static CurrentDirectory property on the Environment class.
>
>     Hope this helps.

I don't like to post code because it always gets messy but the way it is
  set up is like this...

private void bttn_openTabFile_Click(object sender, EventArgs e)
{       
    OpenFileDialog dlgOpenFile = new OpenFileDialog();
         dlgOpenFile.ShowReadOnly = true;
         dlgOpenFile.InitialDirectory = s_defaultPath;

    //the rest of the code in method the only other OpenFileDialog method
is dlgOpenFile.ShowDialog() and it all seems fine
}

whats wrong with that ?, driving me spare...

thanks for your help.

--
Eps
Author
7 Apr 2005 5:04 PM
Wayne
Not sure if he meant current path or the location of the exe

Current path will return you the apps current path, if you execute an open
file dialog and open a file in a different directory, that will be the
current path. If you want the location of the Executable you would use
Application.ExecutablePath.

If you run this code you will see that the path of each is different.

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
MessageBox.Show(Environment.CurrentDirectory);
MessageBox.Show(Path.GetDirectoryName(Application.ExecutablePath));
}


--
Thanks
Wayne Sepega
Jacksonville, Fl

Enterprise Library Configuration Console Module Generator
http://workspaces.gotdotnet.com/elccmg

"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

Show quoteHide quote
"Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard.caspershouse.com> wrote in
message news:#LuYaF4OFHA.3788@tk2msftngp13.phx.gbl...
> Eps,
>
>     Are you using the same instance for each time, or are you using a
> different instance of the OpenFileDialog each time?
>
>     Also, to get the current path where the program is being run from, use
> the static CurrentDirectory property on the Environment class.
>
>     Hope this helps.
>
>
> --
>                - Nicholas Paldino [.NET/C# MVP]
>                - mvp@spam.guard.caspershouse.com
>
> "Eps" <e**@mailinator.com> wrote in message
> news:d33h0o$eb9$1@domitilla.aioe.org...
> >I have a problem that is driving me crazy, I have and openfiledialog but
I
> >can't seem to set its initial path.
> >
> > I have the  initalDirecotry property set to the correct path but it
always
> > opens at the last directory I opened a file in.
> >
> > Does anyone have any idea how I can fix this ?.
> >
> > Also is there any way to get the current path from where a program is
> > being run from ?
> >
> > Any help appreciated.
> >
> > --
> > Eps
>
>
Author
7 Apr 2005 2:55 PM
Claire
Application.ExecutablePath
Are you sure you've set the path correctly?
Ive just put
dlgOpen.InitialDirectory = "C:\\temp";

dlgOpen.ShowDialog();

This works fine.

Have you set some flag, eg restoredirectory to true? (no idea if that makes
a difference)



Post Thread options