Solved

Still exporting text, and a further question

Posted on 2013-01-01
3
290 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now