0

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.

2 Answers2

0

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-' ( e.g.: '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.

Community
  • 1
  • 1
-1
try this 
 OpenFileDialog ofd = new OpenFileDialog() { Filter = "RWS Save Files (*.rws)|*.rws", ValidateNames = true, Multiselect = false, Title = "RWS File Locator", FileName = "Autosave-*" };
        ofd.ShowDialog();
Maheswari
  • 55
  • 3
  • 1
    This does the same thing as the ops example, it only shows files starting with Autosave, not what he wants – HasaniH Aug 12 '16 at 20:22
  • While this code snippet may solve the question, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, as this reduces the readability of both the code and the explanations! – Blue Aug 13 '16 at 09:11