|
-
Aug 30th, 2003, 02:26 AM
#1
Thread Starter
Junior Member
Save File Dialog question
Hello everyone, I tried to save some order input to a text file. The saved text file doesn't show the information, just a blank text file. Below is a piece of code that I wrote. Please adivise what need to be corrected. Thanks a lot guys.
-------------------------------------------------------------------------------
Private Sub mnuExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExport.Click
'Save the sample text to a file.
Dim filenum As Integer
Dim xyz As New frmOrder()
Dim i As Integer
'Separate the path from the location
i = System.Reflection.Assembly.GetExecutingAssembly.Location.Length
While Mid(System.Reflection.Assembly.GetExecutingAssembly.Location, i, 1) <> "\"
i -= 1
End While
'Remember the path for later reference
path = System.Reflection.Assembly.GetExecutingAssembly.Location.Substring(0, i - 1)
SaveFileDialog1.InitialDirectory = path
SaveFileDialog1.ShowDialog()
MsgBox("Your sample text is saved in the following location: " & SaveFileDialog1.FileName)
filenum = FreeFile()
FileOpen(filenum, SaveFileDialog1.FileName, OpenMode.Output)
PrintLine(filenum, xyz.txtOrderNo.Text)
FileClose(filenum)
End Sub
-
Aug 30th, 2003, 04:41 AM
#2
are you trying to save an embedded textfile from the app to a textfile on the HD? if so try this...
VB Code:
[COLOR=BLUE]Dim[/COLOR] sourceTxt [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]String[/COLOR] = Application.ProductName & ".TextFile1.txt"
[COLOR=BLUE]Dim[/COLOR] saveDg [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]New[/COLOR] SaveFileDialog()
[COLOR=BLUE]Dim[/COLOR] sr [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]New[/COLOR] IO.StreamReader([COLOR=BLUE]Me[/COLOR].GetType.Assembly.GetManifestResourceStream(sourceTxt))
[COLOR=BLUE]With[/COLOR] saveDg
.InitialDirectory = "D:\"
.Filter = "Textfiles(*.txt)|*.txt"
[COLOR=BLUE]If[/COLOR] saveDg.ShowDialog = DialogResult.OK [COLOR=BLUE]Then
[/COLOR] [COLOR=BLUE]Dim[/COLOR] file [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]New[/COLOR] IO.StreamWriter([COLOR=BLUE]New[/COLOR] IO.FileStream(saveDg.FileName, IO.FileMode.OpenOrCreate))
[COLOR=BLUE]While[/COLOR] [COLOR=BLUE]Not[/COLOR] sr.Peek
file.WriteLine(sr.ReadLine)
[COLOR=BLUE]End[/COLOR] [COLOR=BLUE]While
[/COLOR] file.Close()
[COLOR=BLUE]End[/COLOR] [COLOR=BLUE]If
[/COLOR] sr.Close()
[COLOR=BLUE]End[/COLOR] [COLOR=BLUE]With[/COLOR]
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Aug 30th, 2003, 01:28 PM
#3
Thread Starter
Junior Member
Thank you. I'll try that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|