Results 1 to 3 of 3

Thread: Save File Dialog question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    16

    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

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    are you trying to save an embedded textfile from the app to a textfile on the HD? if so try this...
    VB Code:
    1. [COLOR=BLUE]Dim[/COLOR] sourceTxt [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]String[/COLOR] = Application.ProductName & ".TextFile1.txt"
    2.         [COLOR=BLUE]Dim[/COLOR] saveDg [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]New[/COLOR] SaveFileDialog()
    3.         [COLOR=BLUE]Dim[/COLOR] sr [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]New[/COLOR] IO.StreamReader([COLOR=BLUE]Me[/COLOR].GetType.Assembly.GetManifestResourceStream(sourceTxt))
    4.         [COLOR=BLUE]With[/COLOR] saveDg
    5.             .InitialDirectory = "D:\"
    6.             .Filter = "Textfiles(*.txt)|*.txt"
    7.             [COLOR=BLUE]If[/COLOR] saveDg.ShowDialog = DialogResult.OK [COLOR=BLUE]Then
    8. [/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))
    9.                 [COLOR=BLUE]While[/COLOR] [COLOR=BLUE]Not[/COLOR] sr.Peek
    10.                     file.WriteLine(sr.ReadLine)
    11.                 [COLOR=BLUE]End[/COLOR] [COLOR=BLUE]While
    12. [/COLOR]                file.Close()
    13.             [COLOR=BLUE]End[/COLOR] [COLOR=BLUE]If
    14. [/COLOR]            sr.Close()
    15.         [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]

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Posts
    16
    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
  •  



Click Here to Expand Forum to Full Width