CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: SaveFileDialog

  1. #1
    Join Date
    Oct 2000
    Posts
    58

    SaveFileDialog

    I need help with saving value from text box to a file using SaveFileDialog. Here is my code, what am I doing wrong?

    Thanks

    Dim myStream As Stream
    Dim saveFileDialog1 As New SaveFileDialog()

    saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
    saveFileDialog1.FilterIndex = 2
    saveFileDialog1.RestoreDirectory = True
    saveFileDialog1.AddExtension = True
    saveFileDialog1.OverwritePrompt = True
    saveFileDialog1.DefaultExt = ".txt"

    If saveFileDialog1.ShowDialog() = DialogResult.OK Then
    myStream = saveFileDialog1.OpenFile()
    If Not (myStream Is Nothing) Then
    If myStream.CanRead And myStream.CanWrite Then
    Console.Write(TextBox1.Text)
    End If
    myStream.Close()
    End If
    End If

  2. #2
    Join Date
    Oct 2002
    Location
    Växjö, Sweden
    Posts
    225
    Is it something like this you had in mind?

    Dim saveFileDialog1 As New SaveFileDialog()

    saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
    saveFileDialog1.FilterIndex = 2
    saveFileDialog1.RestoreDirectory = True
    saveFileDialog1.AddExtension = True
    saveFileDialog1.OverwritePrompt = True
    saveFileDialog1.DefaultExt = ".txt"

    If saveFileDialog1.ShowDialog() = DialogResult.OK Then
    Dim sw As New System.IO.StreamWriter(saveFileDialog1.OpenFile)
    If Not (sw Is Nothing) Then
    sw.Write(TextBox1.Text)
    End If
    sw.Close()
    End If

    /Leyan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured