OpenFileDialog Problem

  • Thread starter Nagachandra Sekhar Grandhi
  • Start date
N

Nagachandra Sekhar Grandhi

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 Explorer i am
getting error saying that cannot delete that folder as some process is using
it. After that i selected a file from the same folder in OpenFileDialog.
When i tried to delete the folder after selecting the file also it is giving
the same error.

My code is as follows.

private void diagramButton_Click(object sender, System.EventArgs e)

{

openFileDialog = new OpenFileDialog();

openFileDialog.Filter = "All Files (*.*)|*.*";

openFileDialog.InitialDirectory = "C:\\temp";

openFileDialog.Multiselect = false;

openFileDialog.RestoreDirectory = false;

this.openFileDialog.ShowDialog(this);

if (openFileDialog.FileName.Trim() != string.Empty) {

this.textBox1.Text = openFileDialog.FileName.Trim();

}

openFileDialog.Dispose();

openFileDialog = null;

}


Please tell me the solution for this ASAP.
 
M

Miha Markic [MVP C#]

Hi,

Are you sure that this isn't a problem with explorer?
I often get such error when I have the folder that I want to delete opened
within explorer...
 
N

Nagachandra Sekhar Grandhi

Yes..I am sure...The problem is not with the explorer. Because after closing
my application i am able to delete the same folder from the same explorer
window.

-chandu.

Miha Markic said:
Hi,

Are you sure that this isn't a problem with explorer?
I often get such error when I have the folder that I want to delete opened
within explorer...

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Nagachandra Sekhar Grandhi said:
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 Explorer
i
am
getting error saying that cannot delete that folder as some process is using
it. After that i selected a file from the same folder in OpenFileDialog.
When i tried to delete the folder after selecting the file also it is giving
the same error.

My code is as follows.

private void diagramButton_Click(object sender, System.EventArgs e)

{

openFileDialog = new OpenFileDialog();

openFileDialog.Filter = "All Files (*.*)|*.*";

openFileDialog.InitialDirectory = "C:\\temp";

openFileDialog.Multiselect = false;

openFileDialog.RestoreDirectory = false;

this.openFileDialog.ShowDialog(this);

if (openFileDialog.FileName.Trim() != string.Empty) {

this.textBox1.Text = openFileDialog.FileName.Trim();

}

openFileDialog.Dispose();

openFileDialog = null;

}


Please tell me the solution for this ASAP.
 
N

Nagachandra Sekhar Grandhi

If you observe my code there is a statement in my code.

openFileDialog.RestoreDirectory = false;

RestoreDirectory property is set to false means the dialog box doesn't
restore the current directory before closing. I made it to true so that it
restores the current directory. Now i can delete the folder from explorer
after closing the openfiledialog. But here i just want to know the current
directory means the directory in which the application is running or the
directory i gave as initial directory.

Please explain this.

Thanks,
Chandu.

Nagachandra Sekhar Grandhi said:
Yes..I am sure...The problem is not with the explorer. Because after closing
my application i am able to delete the same folder from the same explorer
window.

-chandu.

Miha Markic said:
Hi,

Are you sure that this isn't a problem with explorer?
I often get such error when I have the folder that I want to delete opened
within explorer...

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Nagachandra Sekhar Grandhi said:
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
Explorer
 
M

Michael A. Covington

Microsoft documents this somewhere. The behavior of open file dialogs
(i.e., the initial directory that they start up in) is not what you would
think, and is not the same in different versions of Windows. Basically,
Windows tries to remember where you most recently opened a file with that
extension, and it goes there. But the scheme for doing this varies among
versions.

As best I can make out, RestoreDirectory has to do with the current
directory in which the program is running; it has little effect on where the
dialogs open up.


Nagachandra Sekhar Grandhi said:
If you observe my code there is a statement in my code.

openFileDialog.RestoreDirectory = false;

RestoreDirectory property is set to false means the dialog box doesn't
restore the current directory before closing. I made it to true so that it
restores the current directory. Now i can delete the folder from explorer
after closing the openfiledialog. But here i just want to know the current
directory means the directory in which the application is running or the
directory i gave as initial directory.

Please explain this.

Thanks,
Chandu.

Nagachandra Sekhar Grandhi said:
Yes..I am sure...The problem is not with the explorer. Because after closing
my application i am able to delete the same folder from the same explorer
window.

-chandu.

Miha Markic said:
Hi,

Are you sure that this isn't a problem with explorer?
I often get such error when I have the folder that I want to delete opened
within explorer...

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

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
Explorer
i
am
getting error saying that cannot delete that folder as some process is
using
it. After that i selected a file from the same folder in OpenFileDialog.
When i tried to delete the folder after selecting the file also it is
giving
the same error.

My code is as follows.

private void diagramButton_Click(object sender, System.EventArgs e)

{

openFileDialog = new OpenFileDialog();

openFileDialog.Filter = "All Files (*.*)|*.*";

openFileDialog.InitialDirectory = "C:\\temp";

openFileDialog.Multiselect = false;

openFileDialog.RestoreDirectory = false;

this.openFileDialog.ShowDialog(this);

if (openFileDialog.FileName.Trim() != string.Empty) {

this.textBox1.Text = openFileDialog.FileName.Trim();

}

openFileDialog.Dispose();

openFileDialog = null;

}


Please tell me the solution for this ASAP.
 

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

Top