|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
initial directory of openfiledialogI 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 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. -- Show quoteHide quote- 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 Nicholas Paldino [.NET/C# MVP] wrote:
> Eps, I don't like to post code because it always gets messy but the way it is > > 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. 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 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)); } -- Show quoteHide quoteThanks 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 "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 > > 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)
Watching memory use. What tools can I use
Calling an internal constructor Listview problems Default values and form inheritace Strongly typed datasets and nested repeaters Re: c# is a good way to learn c Using arrays to display a date. User control has no impact on parent control Windows Mobile, Pocket PC, PDA, etc. question Canceling selecting a different item in a ListView |
|||||||||||||||||||||||