我想从textbox
输入例如VB
中创建一个文件夹。我有一个“浏览”按钮,一个textbox1
和一个“创建文件夹”按钮,我想创建一个文件夹,从浏览到用户想要创建文件夹的文件系统位置,并且所选位置应该被复制到textbox1
那么用户应该点击“创建文件夹”按钮;如果该文件夹没有退出,则应该说对话框应该说该文件夹已成功创建,如果文件夹存在它应该说,该文件夹已经存在。
所有帮助非常感谢。谢谢。从视觉基本输入文本框中创建文件夹
这是我想到目前为止写代码:
Imports System.IO
Public Class Form1
Dim FolderName As String
Private Function CreateFolder()
FolderName = TextBox1.Text
My.Computer.FileSystem.CreateDirectory("" & FolderName & "")
If My.Computer.FileSystem.DirectoryExists("" & FolderName & "") = False Then
Throw New Exception("The specified path does not exist.")
Else
If My.Computer.FileSystem.DirectoryExists("" & FolderName & "") Then
Throw New Exception("Could not create the folder because it already exists.")
End If
End Function
Private Sub FolderCreate()
CreateFolder()
If Not My.Computer.FileSystem.DirectoryExists("" & FolderName & "") Then
Throw New Exception("The folder creation failed.")
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FolderCreate()
End Sub
Private Sub browse_Click(sender As Object, e As EventArgs) Handles browse.Click
If (FolderBrowserDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
TextBox1.Text = FolderBrowserDialog1.SelectedPath
End If
End Sub
End Class
嗨Capellan,你是绝对正确的,我不认为我需要创建的文件夹从文本框中,但从FolderBrowserDialog这是好得多,我会放下“创建文件夹”按钮,你知道什么,我将使用FolderBrowserDialog dilaog创建文件夹,然后选定的文件夹将显示在“ TextBox1" 的。谢谢你的帮助 – 2014-10-17 13:21:15