How to save a file in VB 6

5 pts.
Visual Basic 6
How to save any type of file to a particular folder after we get the file from common dialog control in VB 6.0

Answer Wiki

Thanks. We'll let you know when a new response is added.

The common dialog control does not open or save the files, it just show a dialog in which the user can select the files.
If you want to modify and save the file selected by the user, after the call to the common dialog you need to open the file, for append/output, write what you need, and then close the file.

Here is an example:

<pre>Private Sub Command2_Click()
' Set filters.
CommonDialog1.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
' Specify default filter.
CommonDialog1.FilterIndex = 2
' Display the Open dialog box.
' get a free file number
file1 = FreeFile
'open the file
Open CommonDialog1.FileName For Append As file1
' Add some text to the file
Print #file1, "This is the new line"
Close #file1
End Sub</pre>

The file name contains the full path.

You could also open 2 files, one for input, and other (in some different location) for output, and write in the second file what you read from the first one.

Hope this helps.

Discuss This Question: 3  Replies

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • akinsdy
    i need to upload a pdf file from one directory and save into another directory using common dialog box
    10 pointsBadges:
  • carlosdl
    Akinsdy, please create a new question including all the necessary details, to make sure your question gets the attention it needs.
    84,495 pointsBadges:
  • R2D2xx
    Normal 0 false false false MicrosoftInternetExplorer4

    Private Sub Command1_Click()

    Dim strNewFile As String

    ' display Common Dialog and choose a file
    strNewFile = CommonDialog1.FileName

    ' strNewFile will look like this: "C:\My Documents\June Report.pdf"
    ' use the Dir function or create your own code to extract the file name
    ' eventually, strNewFile should be "June Report.pdf"

    ' use FileCopy command to save the file into the target folder
    FileCopy strNewFile, ("C:\Sales Reports\" & strNewFile)

    End Sub

    /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} I hope this helps!

    10 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: