Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Still exporting text, and a further question

Posted on 2013-01-01
3
293 Views
Last Modified: 2013-01-01
Hi:  I've been plugging away at exporting text from VB 2010.  Moving right along, but now Im at the stage where I want to deliver a prompt to users to allow them to select or enter a filename.  In short, I'm including a savefiledialog code with streamwriter code; I don't know where to insert the savefiledialog code.  Below is what I have so far:

Dim objFile As New System.IO.StreamWriter(SaveFileDialog1, True)

        SaveFileDialog1.Title = "Specify Desitination Filename"
        SaveFileDialog1.Filter = "Text Files (*.txt)|*.txt"
        SaveFileDialog1.FilterIndex = 1

        objFile.WriteLine(RichTextBox1.Text)
        objFile.Close()

Thanks in advance.  Robert
0
Comment
Question by:RobertGeoff
3 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 38734971
Use the ShowDialog() method and only save the file if "OK" is returned:
    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        SaveFileDialog1.Title = "Specify Desitination Filename"
        SaveFileDialog1.Filter = "Text Files (*.txt)|*.txt"
        SaveFileDialog1.FilterIndex = 1

        If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Using objFile As New System.IO.StreamWriter(SaveFileDialog1.FileName, True)
                objFile.WriteLine(RichTextBox1.Text)
            End Using
        End If
    End Sub

Open in new window

0
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 38735204
I will use WriteAllText instead of streaming the file. Replace lines 6 to 8  of previous post with:

System.IO.File.WriteAllText(SaveFileDialog1.FileName, RichTextBox1.Text)
0
 

Author Closing Comment

by:RobertGeoff
ID: 38735458
Thank you both for you help.  The second modification offered returned an exception, however.  Robert
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question