简体   繁体   English

在Visual Basic中过滤保存文件对话框中的文件夹

[英]Filtering Folders in Save File Dialog in Visual Basic

I am making an application in Visual Basic which creates a directory and places text files in them, but I want to view a directory in which the user wants the text files from. 我在Visual Basic中创建一个应用程序,它创建一个目录并在其中放置文本文件,但我想查看用户想要文本文件的目录。 I have decided that using the OpenFileDialog option would work best. 我已经决定使用OpenFileDialog选项会效果最好。 What filter would I use for the OpenFileDialog ? 我将为OpenFileDialog使用什么过滤器?

For the creation of the folder and documents: 用于创建文件夹和文档:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Computer.FileSystem.CreateDirectory("C:/Organizer/" + BusinessName.Text)

        Dim objWriter9 As New System.IO.StreamWriter("C:/Organizer/" + BusinessName.Text + "/" + "Address" + ".txt")
        objWriter9.Write(Address.Text)
        objWriter9.Close()

        Dim objWriter As New System.IO.StreamWriter("C:/Organizer/" + BusinessName.Text + "/" + "BusinessName" + ".txt")
        objWriter.Write(BusinessName.Text)
        objWriter.Close()

        Dim objWriter1 As New System.IO.StreamWriter("C:/Organizer/" + BusinessName.Text + "/" + "AssociateName" + ".txt")
        objWriter1.Write(AssociateName.Text)
        objWriter1.Close()

        Dim objWriter2 As New System.IO.StreamWriter("C:/Organizer/" + BusinessName.Text + "/" + "PhoneNumber" + ".txt")
        objWriter2.Write(PhoneNumber.Text)
        objWriter2.Close()

        Dim objWriter3 As New System.IO.StreamWriter("C:/Organizer/" + BusinessName.Text + "/" + "Email" + ".txt")
        objWriter3.Write(Email.Text)
        objWriter3.Close()

        If CheckBox1.Checked Then
            Dim objWriter4 As New System.IO.StreamWriter("C:/Organizer/" + BusinessName.Text + "/" + "Other" + ".txt")
            objWriter4.Write(Other1.Text)
            objWriter4.Close()
        End If

        If CheckBox5.Checked Then
            Dim objWriter5 As New System.IO.StreamWriter("C:/Organizer/" + BusinessName.Text + "/" + BusinessName.Text + "Other1" + ".txt")
            objWriter5.Write(Other3.Text)
            objWriter5.Close()
        End If

        If CheckBox4.Checked Then
            Dim objWriter6 As New System.IO.StreamWriter("C:/Organizer/" + BusinessName.Text + "/" + BusinessName.Text + "Other2" + ".txt")
            objWriter6.Write(Other5.Text)
            objWriter6.Close()
        End If

        If CheckBox3.Checked Then

        End If
        Dim objWriter7 As New System.IO.StreamWriter("C:/Organizer/" + BusinessName.Text + "/" + BusinessName.Text + "Other3" + ".txt")
        objWriter7.Write(Other7.Text)
        objWriter7.Close()

        If CheckBox5.Checked Then
            Dim objWriter8 As New System.IO.StreamWriter("C:/Organizer/" + BusinessName.Text + "/" + BusinessName.Text + "Other4" + ".txt")
            objWriter8.Write(Other9.Text)
            objWriter8.Close()
        End If

    End Sub
End Class

And for the loading of it (so far): 并加载它(到目前为止):

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Button1.Hide()
    Label1.Show()
    Label2.Show()
    Label3.Show()
    Label4.Show()
    Label5.Show()
    Label6.Show()
    Label7.Show()
    Label8.Show()
    Label9.Show()
    Label10.Show()
    Label11.Show()
    Label12.Show()
    Label13.Show()
    Label14.Show()
    Label15.Show()
    Label16.Show()
    Label17.Show()
    OpenFileDialog1.InitialDirectory = "C:/Organizer"
    OpenFileDialog1.Filter = "Folder|"
    OpenFileDialog1.ShowDialog()
    My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)

我意识到,我可以使用FolderBrowserDialog而不是使用OpenFileDialog

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM