Solved

Still exporting text, and a further question

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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 …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

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