none
Creating a folder on fileSaveDialog and displaying contents

    Question

  • Hi, i can do both save and create a directory, but my issue is with automatically creating a prenamed folder when and where the user saves his document.

    What i am trying to do is create a folder called images at the same time and same place the user saves his work. Is this possible and if so can anyone guide me on this one?
    Here is my save code so far, (hoping it's the correct way).

        Private Sub SaveToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SaveToolStripMenuItem.Click
            Dim saveFileDialog1 As New SaveFileDialog()
            saveFileDialog1.Filter = "html Files (*.html)|*.html"
            saveFileDialog1.Title = "Save your Page"
            If saveFileDialog1.ShowDialog() = DialogResult.OK Then
                Dim sw As StreamWriter = New StreamWriter(saveFileDialog1.OpenFile())
                If (sw IsNot Nothing) Then
                    sw.WriteLine(RTShtmlBox.Text)
                    sw.Close()
                End If
            End If
        End Sub

    I just can't figure out where or how to code in the folder creation (images).

    Thanks in advance.


    regards Flatland France


    Saturday, October 08, 2016 1:34 PM

Answers

  • Try this:

    If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
    
        Dim new_folder = Path.Combine(Path.GetDirectoryName(SaveFileDialog1.FileName), "Images")
        Directory.CreateDirectory(new_folder)
    
    . . .

    If you want to save some files in that folder, then create paths like this: Dim name = Path.Combine(new_folder, "MyImage.jpg").

    • Marked as answer by EyeMan Android Saturday, October 08, 2016 3:20 PM
    Saturday, October 08, 2016 2:58 PM

All replies

  • Try this:

    If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
    
        Dim new_folder = Path.Combine(Path.GetDirectoryName(SaveFileDialog1.FileName), "Images")
        Directory.CreateDirectory(new_folder)
    
    . . .

    If you want to save some files in that folder, then create paths like this: Dim name = Path.Combine(new_folder, "MyImage.jpg").

    • Marked as answer by EyeMan Android Saturday, October 08, 2016 3:20 PM
    Saturday, October 08, 2016 2:58 PM
  • Out of the box, thank you Viorel.

    That's exactly what i was looking for.

    regards Flatland France

    Saturday, October 08, 2016 3:21 PM