Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving File Name as a String from a Text Box

Status
Not open for further replies.

tekrobg

Programmer
Oct 12, 2004
42
US
I want my SaveFileDialog to put the string from a text box as the name to save the file as. For example: the user enters "My File Name" in a text box. I want "My File Name" to show up in the SaveFileDialog Box as the file name to save as.

Here is my code for the button click:

vb/
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SaveFileDialog1.ShowDialog()
RichTextBox1.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
End Sub
/vb

Thanks for any help.
 
You can use the same method as reading the name back from the SaveFileDialog.

Code:
SaveFileDialog1.FileName = txtFileName.text

This will show the name typed in when SaveFileDialog is opened.

-Kris
 
It seems like that should work, but it doesn't put the string from the text box in the "File Name" box of the SaveFileDialog box.

Any other ideas?

Should the line look like this?

RichTextBox1.SaveFile(SaveFileDialog1.FileName = TextBox3.Text, RichTextBoxStreamType.PlainText)
 
Don't know why it is not workig for you. Actually it should work, thats what I do all the time. MSDN also refers to the same property to get/set values to DialogBox FileName.

-Kris
 
Hi,

Well just a quicky test... I am unfamilar with the way you are doing it parameterizing it.. But

This works:
Me.SaveFileDialog1.FileName = Me.TextBox1.Text
Me.SaveFileDialog1.ShowDialog()

Now notice the order... because if you try and set the filename after you call show dialong it WONT work.

This does *not* work

Me.SaveFileDialog1.ShowDialog()
Me.SaveFileDialog1.FileName = Me.TextBox1.Text

So make sure that you assign the filename BEFORE you call the showdialog.

Don't know if this helps...But that is the only thing I could think of

Angela
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top