Paul Williams
Paul Williams

Reputation: 1598

Using one Save File Dialog Box in Visual Basic

Currently I have three separate save commands in my program: Write to Plain Text, Write to HTML, and Write to Excel File.

Each one is invoked by a different command on a menu. I would like to combine these three into one Save File Dialog on the program. I know that I would have to edit the "Filter" property of the dialog box to add in the other two types.

My questions, how do I code the program to save the file based off what is chosen from the filter. That's to say :

If "Selected = Microsoft Excel" Then
    * Save As Excel File
ElseIf "Selected = HTML Then
    * Save As HTML File
Else 
    * Save As Plain Text File
End If

Thanks for any response.

Upvotes: 1

Views: 5262

Answers (1)

ispiro
ispiro

Reputation: 27673

Here's a snippet to give you an idea. Sorry it's in C#, but it should be easy to convert to VB.

EDIT: here's the new code:

saveFileDialog1.Filter = "Text|*.txt|Word|*.docx";
saveFileDialog1.ShowDialog();            
if (saveFileDialog1.FilterIndex == 2) MessageBox.Show("It's a Word doc.");
saveFileDialog1.Dispose();

Upvotes: 1

Related Questions