Using Save file Dialog
Using Save file Dialog
Using Save file Dialog
Using Save file Dialog
Using Save file Dialog
Using Save file Dialog Using Save file Dialog Using Save file Dialog Using Save file Dialog Using Save file Dialog Using Save file Dialog Using Save file Dialog Using Save file Dialog
Using Save file Dialog Using Save file Dialog
Using Save file Dialog
Go Back  Xtreme Visual Basic Talk > > > Using Save file Dialog


Reply
 
Thread Tools Display Modes
  #1  
Old 08-16-2004, 09:54 AM
sramey sramey is offline
Newcomer
 
Join Date: Apr 2004
Posts: 7
Default Using Save file Dialog


Hi I'm having trouble using the save file dialog box to save a text file. I learned how to open files via MSDN help, but I can't figure out how to save the files. When save dialog comes up it allows me to put in a file name and click save but I can't open that file again anywhere. Here is the code I have now.

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim myStream As Stream
Dim saveFileDialog1 As New SaveFileDialog
With sfd
.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
.FilterIndex = 2
.RestoreDirectory = True

If sfd.ShowDialog() = DialogResult.OK Then
myStream = sfd.OpenFile()
If Not (myStream Is Nothing) Then
myStream.Close()
End If
End If
End With
End Sub

I know I'm missing something, but what am I missing.
Thanks
Sandra
Reply With Quote
  #2  
Old 08-16-2004, 11:05 AM
Dennis DVR's Avatar
Dennis DVRUsing Save file Dialog Dennis DVR is offline
Back in the Game

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Manila Philippines
Posts: 3,576
Default

are you really saaving the file it looks that you are opening an existing file is that really your code for saving or it is really your code for opening the file?

you want to save a txt file then the code would look similar to this
Code:
If SaveFileDialog1.ShowDialog() = SaveFileDialog1.OK Then Dim strFileName As String Dim myStream As StreamWriter = New StreamWriter(strFileName, False) myStream.Write(TextToSave) myStream.Close() myStream = Nothing End If
__________________
Avatar by Lebb

[Posting Guidelines] [Standards & Practices Tutorial] [Participate here effectively]
Our knowledge can only be finite, while our ignorance must necessarily be infinite. Karl Popper
Reply With Quote
  #3  
Old 08-16-2004, 11:33 AM
sramey sramey is offline
Newcomer
 
Join Date: Apr 2004
Posts: 7
Default

That was suppose to be the save code. But like I said I'm not sure what I'm doing when it comes to saving files.
Reply With Quote
  #4  
Old 08-16-2004, 11:49 AM
MKoslof's Avatar
MKoslofUsing Save file Dialog MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

OK, do you want to open an EXISTING text file and do a save as (move it to a different location?). Or do you want to create a NEW text file, write data to it, and then conduct a save of this new file. If the file already exists and you are attempting to read it...you don't need to save it, unless you want to physically copy the file to another location or conduct a save as.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #5  
Old 08-17-2004, 11:04 AM
sramey sramey is offline
Newcomer
 
Join Date: Apr 2004
Posts: 7
Default

Quote:
Originally Posted by MKoslof
OK, do you want to open an EXISTING text file and do a save as (move it to a different location?). Or do you want to create a NEW text file, write data to it, and then conduct a save of this new file. If the file already exists and you are attempting to read it...you don't need to save it, unless you want to physically copy the file to another location or conduct a save as.
I would like to be able to make new files. Is there a certain container I have to use in order to make changes to text. Like a text box?
Reply With Quote
  #6  
Old 08-17-2004, 12:58 PM
MKoslof's Avatar
MKoslofUsing Save file Dialog MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Use the streamwriter to create a new text file and save it to a specified location.

Code:
Dim myLog as StreamWriter myLog = New StreamWriter(Environment.CurrentDirectory & "\TextName.txt") myLog.WriteLine("Just writing the date, an example: - " & Date.Now.ToString) myLog.WriteLine("Goodbye") myLog.Flush myLog.Close
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #7  
Old 08-17-2004, 02:15 PM
sramey sramey is offline
Newcomer
 
Join Date: Apr 2004
Posts: 7
Default

Quote:
Originally Posted by MKoslof
Use the streamwriter to create a new text file and save it to a specified location.

Code:
Dim myLog as StreamWriter myLog = New StreamWriter(Environment.CurrentDirectory & "\TextName.txt") myLog.WriteLine("Just writing the date, an example: - " & Date.Now.ToString) myLog.WriteLine("Goodbye") myLog.Flush myLog.Close
Thanks hopefully this will do it.
Reply With Quote
  #8  
Old 08-17-2004, 02:17 PM
MKoslof's Avatar
MKoslofUsing Save file Dialog MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Good luck.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Using Save file Dialog
Using Save file Dialog
Using Save file Dialog Using Save file Dialog
Using Save file Dialog
Using Save file Dialog
Using Save file Dialog Using Save file Dialog Using Save file Dialog Using Save file Dialog Using Save file Dialog Using Save file Dialog Using Save file Dialog
Using Save file Dialog
Using Save file Dialog
 
Using Save file Dialog
Using Save file Dialog
 
-->