I Have a folder in this path
C:\Users\XXX\Desktop\Original\XXX\bin\Debug\Backup
And when I save my project with “XXX” name the same time I need to change the Backup Folder using that save filedialog name and it shouldn’t overwrite it.
Can anyone suggest me how to do this:
Here is the code how I am doing it and it didn’t work for me:
Private Sub SaveProject_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveProject.Click
Using sfdlg As New Windows.Forms.SaveFileDialog
sfdlg.OverwritePrompt = True
sfdlg.InitialDirectory = "C:\"
sfdlg.FileName = "Untitled"
sfdlg.DefaultExt = "amk"
sfdlg.Filter = "AquaMark Project|*.amk"
If sfdlg.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim SaveData As New gCanvasData
With SaveData
frmDisplay.GCanvas1.UnselectCurrentAnotate()
.gAnnotates = frmDisplay.GCanvas1.gAnnotates
.Image = frmDisplay.GCanvas1.Image
End With
Using objStreamWriter As New StreamWriter(sfdlg.FileName)
Dim x As New XmlSerializer(GetType(gCanvasData))
x.Serialize(objStreamWriter, SaveData)
objStreamWriter.Close()
End Using
End If
sfdlg.Dispose()
System.IO.Path.GetFileNameWithoutExtension(sfdlg.FileName)
IO.Directory.Move(Application.StartupPath + "\Backup\", Application.StartupPath + "\Backup\" & System.IO.Path.GetFileNameWithoutExtension(sfdlg.FileName))
End Using
End Sub
But can anyone clearly mention me how to do it?
Based on the error, you most likely won’t be able to save the file and change the backup folder name through the same SaveFileDialog.
Break it into two steps:
EDIT
As I noted in step 1, you need to save the filename somewhere so you can use it in step 2.