简体   繁体   中英

OpenFileDialog.Filter - name exception

Introduction

Hello, Stackoverflow. I have a question regarding Visual Basic Studio, I just picked it up - just to code something quite specific.

I'm having a problem with the OpenFileDialog.Filter

Code

using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "RWS Save Files (*.rws)|*.rws", ValidateNames = true, Multiselect = false, Title = "RWS File Locator" })

Yes, the file extension is .rws

Problem

The problem lies in the Filter = section, I don't know to create a filter which would exclude a filename starting with Autosave- . Also, the Autosave filename is automatically enumerated, which means that there are multiple files, enumerated as

  • Autosave-1.rws, Autosave-2.rws, Autosave-3.rws, Autosave-4.rws

Closest I came to was Filter = "RWS Save Files (*.rws)|Autosave-*.rws which only displays files starting with Autosave- and since I was unable to find anything on the official msdn.microsoft.com websites regarding Filter filename exclussion - I turn to stackoverflow.

Unfortunately the OpenFileDialog-class is not designed to do what you would like to.

So a workaround might be making the files you want be visible in the dialog start with another definite tag other than 'AutoSave-' ( eg: 'TagToBeSelectedInTheDialog-') and change FileName to "TagToBeSelectedInTheDialog-*".

Otherwise you have to change the file-naming-scheme of your files.

If you still insist on your file-naming-scheme, you could also make your own dialog .

try this 
 OpenFileDialog ofd = new OpenFileDialog() { Filter = "RWS Save Files (*.rws)|*.rws", ValidateNames = true, Multiselect = false, Title = "RWS File Locator", FileName = "Autosave-*" };
        ofd.ShowDialog();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM