Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am new to VB .NET. I am trying to select a file and saving it with another name, but file is not being saved with new name. Kindly advise. The code is:
Private Sub btnOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenFile.Click
OpenFileDialog1.InitialDirectory = "c:\"
OpenFileDialog1.Title = "Select a File"
OpenFileDialog1.Filter = "Text Files|*.txt"
OpenFileDialog1.FilterIndex = 1
If OpenFileDialog1.ShowDialog() <> DialogResult.Cancel Then
txtSource.Text = OpenFileDialog1.FileName
Else
txtSource.Text = ""
End IfEnd Sub
Private Sub btnSaveFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveFile.Click
SaveFileDialog1.Title = "Specify Destination Filename"
SaveFileDialog1.Filter = "Text Files|*.txt"
SaveFileDialog1.FilterIndex = 1
SaveFileDialog1.OverwritePrompt = True
SaveFileDialog1.CreatePrompt = True
If SaveFileDialog1.ShowDialog() <> DialogResult.Cancel Then
txtDestination.Text = SaveFileDialog1.FileNameEnd If
End Sub
karahim

There is nothing in your code that actually saves a file, or opens it for that matter. All you have is two functions to select two different files.
You need to do something with txtSource.Text and txtDestination.Text which are just two text boxes with filenames in them.
You would probably be better just using the Copy command to copy the source to the destination.
Stuart

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |