I'm looking to do a "Save As" dialog box to handle my saves from an application I am making in Visual Basic.
This is the code I am using and I don't understand it the code either:
Private Sub MenuExportTo_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MenuExportTo.Click
Dim myStream As IO.Stream 'I don't understand this line
Dim saveFileDialog1 As New SaveFileDialog() 'I don't understand this line
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
'I understand this
saveFileDialog1.FilterIndex = 1 ' I understand this
saveFileDialog1.RestoreDirectory = True ' I understand this
If saveFileDialog1.ShowDialog() = DialogResult.OK Then
' I don't understand the rest
myStream = saveFileDialog1.OpenFile()
If (myStream IsNot Nothing) Then
' Code to write the stream goes here. (This was what the example
I referenced put here. the important code goes here, but the example was no help)
myStream.Close()
End If
End If
Problem 1: I'm newer at this, no source gives me an in-depth enough explanation to understand what's really going with any saving method. I need a solid explanation, I'm lost here.
Problem 2: I can get the code to write to a text file at a location, but return carets are lost and it saves to the text file all on one line, using this:
My.Computer.FileSystem.WriteAllText("c:\savelocation", TextBox1.Text, False
How do I fix the retun caret problem? Also, How would I make it so the user selects the save location instead of that being part of the code?
Problem 3: How do I get the file path specified by the user, in the save as dialog, into a variable?
Any help, even just an answer to one of my questions would be appreciated! Thanks!