471,338 Members | 1,009 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

openfiledialog filter ?

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.
Sep 15 '08 #1
8 3920
Z.K. wrote:
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
Sep 15 '08 #2
Navid wrote:
Z.K. wrote:
>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

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.
Sep 15 '08 #3
On Mon, 15 Sep 2008 16:46:59 -0700, Z.K. <no****@nospam.netwrote:
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.
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
Sep 16 '08 #4
In what you posted, there is no dot (.) between the * and the sln. You have
*SLN. Try fixing that.

"Z.K." <no****@nospam.netwrote in message
news:en**************@TK2MSFTNGP02.phx.gbl...
>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.
Sep 16 '08 #5
Peter Duniho wrote:
On Mon, 15 Sep 2008 16:46:59 -0700, Z.K. <no****@nospam.netwrote:
>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.

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.
Sep 16 '08 #6
Family Tree Mike wrote:
In what you posted, there is no dot (.) between the * and the sln. You
have *SLN. Try fixing that.

"Z.K." <no****@nospam.netwrote in message
news:en**************@TK2MSFTNGP02.phx.gbl...
>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.

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.
Sep 16 '08 #7
On Mon, 15 Sep 2008 17:34:31 -0700, Z.K. <no****@nospam.netwrote:
Oops, I thought I had.
Well, you posted one line of code. Granted, it was an incorrect line of
code, but it's impossible to know for sure that the error in that line is
the one causing you trouble, when you haven't posted a complete code
sample.
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 (*.*)|*.*";
How would that be different from:

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

?

Pete
Sep 16 '08 #8
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.
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Mon, 15 Sep 2008 17:34:31 -0700, Z.K. <no****@nospam.netwrote:
>Oops, I thought I had.

Well, you posted one line of code. Granted, it was an incorrect line of
code, but it's impossible to know for sure that the error in that line is
the one causing you trouble, when you haven't posted a complete code
sample.
>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 (*.*)|*.*";

How would that be different from:

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

?

Pete
Sep 16 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Lina | last post: by
4 posts views Thread by Nagachandra Sekhar Grandhi | last post: by
4 posts views Thread by Michael Grosse | last post: by
6 posts views Thread by barbara_dave | last post: by
6 posts views Thread by Mike | last post: by

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.