openfiledialog filter ?

Z

Z.K.

I would like to display two different types of files when bringing up
the OpenFileDialog, but I can't seem to figure out how to do this. I
can manage a single file type or all file types, but not just the ones
that I want. I used the statement before and though it displays the
*.csproj files it does not display the *.sln files.

openFileDialog.Filter = "Solution Files (*.sln) And Project Files
(*.csproj)|*sln ;*.csproj|All Files (*.*)|*.*";


Can someone tell me what I am doing wrong?

Z.K.
 
N

Navid

Z.K. said:
I would like to display two different types of files when bringing up
the OpenFileDialog, but I can't seem to figure out how to do this. I
can manage a single file type or all file types, but not just the ones
that I want. I used the statement before and though it displays the
*.csproj files it does not display the *.sln files.

openFileDialog.Filter = "Solution Files (*.sln) And Project Files
(*.csproj)|*sln ;*.csproj|All Files (*.*)|*.*";


Can someone tell me what I am doing wrong?

Z.K.

I think you are looking for something like :
OpenFileDialog openFileDlg = new OpenFileDialog();
openFileDlg.Filter = "Text Files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDlg.FilterIndex = 1;

this displays All files and .txt files
 
Z

Z.K.

Navid said:
I think you are looking for something like :
OpenFileDialog openFileDlg = new OpenFileDialog();
openFileDlg.Filter = "Text Files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDlg.FilterIndex = 1;

this displays All files and .txt files


Actually, that is not what I am looking for. I can display single file
types or all file types just fine. It is only when I try to display
only certain file types that it does not work. Supposedly though it is
possible as I found this on a web site: MyFileOpen.Filter = "ASCII files
(*.txt;*.log)|*.txt;*.log". I thought I was doing basically the same
thing, but I can not get it to work. I guess I will jsut have to use
all files for the time being until I figure it out.

Z.K.
 
F

Family Tree Mike

In what you posted, there is no dot (.) between the * and the sln. You have
*SLN. Try fixing that.
 
Z

Z.K.

Peter said:
Yes. Unless you post the code you're actually using, it will be
impossible for anyone here to explain what you've done wrong.

Navid's reply was accurate even if simpler than what you want, and the
MSDN documentation is accurate as well (saying substantially the same
thing), as is the web site where you found yet another example. All of
these examples are correct. So, if your code doesn't do what those
examples say they do, you haven't followed the example correctly.

But if you don't post the code, no one could possibly know what mistake
you've made, and you will "just have to use all files for the time
being". I certainly agree with that. :)

Pete


Oops, I thought I had. I figured it out anyway. I knew it was simple I
just got the syntax a bit wrong. I did it like this:
openFileDialog.Filter = "Solution and Project Files
(*.sln;*.csproj)|*.sln;*.csproj|" + "All files (*.*)|*.*";

Thanks anyway though.

Z.K.
 
Z

Z.K.

Family said:
In what you posted, there is no dot (.) between the * and the sln. You
have *SLN. Try fixing that.


Yes, I figure that out, but it did not help. I figured it out anyway as
in openFileDialog.Filter = "Solution and Project Files
(*.sln;*.csproj)|*.sln;*.csproj|" + "All files (*.*)|*.*";

Thanks,

Z.K.
 
F

Family Tree Mike

The original post dropped the . in *.sln, and had a space before the
semi-colon after sln. Once those were fixed, the code worked fine for me.
I think a few things were changed before you saw the post.
 

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