473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

OpenFileDialog Initial Directory not working

I'm a bit confused by this - when I set the InitialDiretory of an
OpenFileDialog to be a subfolder within the same folder as the app, the
file dialog does not initially display the folder - instead it shows
the last used folder (this persists after closing the app).

However, if I use a different path (e.g. "C:\\") then every time the
dialog is shown, it starts at the correct directory every time.

Is there something special about an app path that a file dialog doesn't
like, or is my syntax wrong???

OpenFileDialog objOpenDlg = new OpenFileDialog();
objOpenDlg.InitialDirectory = Application.ExecutablePath + @"\Games\";
if (objOpenDlg.ShowDialog() == DialogResult.OK)
{
//do some stuff here
}

It doesn't seem to make any difference whether the app is a debug or
release mode, and whether it is run from the IDE or not.

Any thoughts???

Greg.

Dec 16 '05 #1
2 7911
Hi Greg,

Use Application.StartupPath instead. Application.ExecutablePath
includes the file name.

objOpenDlg.InitialDirectory = Path.Combine(Application.StartupPath,
"Games");

Regards,
Thi

Dec 16 '05 #2
Excellent, thanks a lot!

Dec 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bob | last post by:
I am working on a Windows Application writing in vb.net. I want something similiar to OpenFileDialog but I do not want the user to leave the initial diredtory. I can check for this upon return but...
4
by: Nagachandra Sekhar Grandhi | last post by:
I am facing a problem with OpenFileDialog. It is as follows. I opened OpenFileDialog dialog box and selected a folder in it. After selecting the folder when i tried to delete the same folder in...
4
by: Eps | last post by:
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...
6
by: barbara_dave | last post by:
Hi, All, I want to use the openfiledialog to open different extension files in different directory( only one type files at one time). I set the OpenFiledialog InitialDirectory and Filter...
14
by: Ithaqua | last post by:
I am having problems giving my dialog box the initial directory at runtime. I can get it working if I code it at design time, does any one know why this code wont allow me to get the initial...
4
by: NickP | last post by:
Hi there, This is really crazy! 1. Make a folder 2. Put a text file in the folder 3. Run the following code... Dim pop As New OpenFileDialog Using pop
1
by: sam | last post by:
OpenFileDialog appears to be "holding onto" the parent folder of a selected file until the application using the dialog quits. After creating a folder containing a file, I attempted to select...
5
by: =?Utf-8?B?UGVy?= | last post by:
I want to change the current path in the OpenFileDialog in runtime. When the user presses OK-button I'm checking the selected path if it's valid for my application. If it's not valid I want to set...
2
by: Peted | last post by:
Hi i have a circumstance where a user unzips a file, with a certain layer of directories to get to a textfile. So in any directory on the HDD they may end up with something like ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.