Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Still exporting text, and a further question

Posted on 2013-01-01
3
Medium Priority
?
298 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
[X]
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
3 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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 36

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

596 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