Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

 

 

I'm having a bit of a problem with OpenFileDialog and FileFilter.

 

This is my code:

 

private void btnBrowse_Click(object sender, EventArgs e) {

OpenFileDialog ofdMsgPath = new OpenFileDialog();

 

ofdMsgPath.CheckFileExists = true;

ofdMsgPath.InitialDirectory = "c:\\";

ofdMsgPath.Filter = "Text files (*.TXT)|*.TXT|HTML files (*.HTM, *.HTML)|*.HTM;*.HTML|All files (*.*)|*.*";

ofdMsgPath.FilterIndex = 1;

ofdMsgPath.RestoreDirectory = true;

ofdMsgPath.ShowReadOnly = true;

ofdMsgPath.ReadOnlyChecked = true;

 

if (ofdMsgPath.ShowDialog() == DialogResult.OK) {

txtFile.Text = ofdMsgPath.FileName;

}

}

 

 

Now, this works fine until I change the filter during runtime which causes the whole content of the current directory to disappear.

 

Also html/htm file icon is replaced with the one for unrecognised file types!?

 

Have no idea what is going wrong.

 

Any help/guidence would be appriciated.

 

Thanks

  • *Experts*
Posted
If you change the filter then the dialog may seem empty as there is no files of the selected type there. If thats not the case I cant help you much here as that or the icon change didnt happen to me when I tested the code.
Posted

I don't think that's the problem as all directories disappear as well.

 

The wierd thing is that I don't remember having this problem few days ago. It must be something I changed along the way.

 

Thanks for you help.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...