Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to use filter by extension on ExplorerBrowser? #501

Open
MrIkso opened this issue Jan 9, 2025 · 6 comments
Open

[Question] How to use filter by extension on ExplorerBrowser? #501

MrIkso opened this issue Jan 9, 2025 · 6 comments

Comments

@MrIkso
Copy link

MrIkso commented Jan 9, 2025

Hi, how to use extension filter on Explorer Browser or another wrapper like as on OpenFileDialog. Currently i'm not found this, in need open /browse files only specific extension not all. Thanks

@tajbender
Copy link
Contributor

tajbender commented Jan 9, 2025

Hi @MrIkso,

You talk about the Filter-Property? For OpenFileDialog, you can find an example here:

https://learn.microsoft.com/en-us/dotnet/desktop/winforms/controls/how-to-open-files-using-the-openfiledialog-component?view=netframeworkdesktop-4.8

See setting the Filter-Property:

        openFileDialog1 = new OpenFileDialog()
        {
            FileName = ...,
            Filter = "Text files (*.txt)|*.txt",
            Title = ...
        };

So, the pattern is "File Type Description | *.extension | File Type 2 Description | *.anotherExtension", you can add as many file types as you wish.

e.g. "JPeg Image|*.jpg|GIF Image|*.gif|My own file extension|*.myFileExt"

The first part of every pair is the Text that will be shown in the DropDownBox within the dialog.
The second part is the extension, as used in Command Prompt (i.e. Dir *.jpg).

Just concatenate each pair of "description / extension" with the separator |. It's been a while, but afaik just giving a pattern matching like Filter = "*.gif" won't work.
In this given example for only gif-files to be from interest, you should use: "Filter = "GIF Image|*.gif""

I hope that helps,
regards,
tajbender

@tajbender
Copy link
Contributor

tajbender commented Jan 9, 2025

BTW, as far I remember you even don't have to provide a description. To filter "unnamed" items with an extension, Filter = "|*.myfilter" (this way the User should only be able to select or enter valid files with pattern "*.myfilter")

If you want to show all items as an option, use something like All Files|*

@tajbender
Copy link
Contributor

@MrIkso
Copy link
Author

MrIkso commented Jan 9, 2025

@tajbender hi, thanks for you answer, Im question for ExplorerBrowser wrapper to make similar to OpenFileDialog with filters

@tajbender
Copy link
Contributor

You are welcome. For ExplorerBrowser, you may use the following approach:

devblogs.microsoft.com/oldnewthing - Applying a filter to the contents of an Explorer Browser

That said, this is one option to filer items in ExplorerBrowser, but I guess it's also the easiest approach.

@tajbender
Copy link
Contributor

Another Addition: @dahall was kind enough to translate the examples from Windows SDK to Vanara:

Look at these examples, they might help getting the point to some of that stuff in reference to the old, plain Windows SDK 7.0 - Examples which do not use Vanara.

These examples are helpful anyways, but someone can also learn how to use the native Windows SDK in conjunction with Vanara.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants