• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 145
  • Last Modified:

VS C# 2008 File Dialog

I am trying to present to the user a textbox that will contain a filename, complete with path, that is derived by providing a lookup to where you want this file to go. The textbox is called txtFileName.

I am trying to follow the example in the code provided below but even though I have included the System.Windows.Forms namespace it does not recognize saveFileDialog1 all I get is saveFileDialog and there is no Filter directive. What am I mssing?
private void btnSave_Click(object sender, EventArgs e)
         {
             saveFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
             saveFileDialog1.FilterIndex = 1;
             if (saveFileDialog1.ShowDialog() == DialogResult.OK)
             {
                 StreamWriter myStream = new StreamWriter(saveFileDialog1.FileName, true);
                 myStream.Write(richTextBox1.Text);
                 myStream.Close();
             }
         }

Open in new window

0
rwheeler23
Asked:
rwheeler23
1 Solution
 
käµfm³d 👽Commented:
SaveFileDialog is a class, and you have to create an instance of it in order to work with it in the manner that you have displayed. For forms, you typically "create" an instance by dragging it onto the form from the "Components" section of the ToolBox.

Are you working with an instance of SaveFileDialog?
0
 
rwheeler23Author Commented:
I see what you mean. I am learning as quickly as I can. Thanks for the tip I have it working now.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now