Create Folder using VB.NET
In VB.Net, sometimes we have require to Create New Folder. This Tutorial Shows How to Create a Folder using VB.NET.
To achieve that, first of all we need to include the following statement in the program code:
Imports System.IO - This line has to precede the whole program code as it is higher in hierarchy for DirectoryInfo. In Fact, this is the concept of object oriented programming where DirectoryInfo is part of the namespace System.IO.
Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New, and choose Windows Form Application.
Finally, select OK, then it creates your project and displays following Form1.
Now, add one button named Button1 for Creating New Folder. Also, add a textbox for the name of the Directory, named it as TextBox1.
The designed application will look like this:
Now, code this statement for Button1:
- Dim di As DirectoryInfo = New DirectoryInfo(TextBox1.Text)
- If di.Exists Then
- MsgBox("That path exists already.")
- MsgBox("Folder Is Created.......!", MsgBoxStyle.Information)
- End If
DirectoryInfo - used to locate and have a directory of a file or folder. It passes the value of the directory as the input of Textbox1.
If directory is already existed (
di.Exists) then it will crear the TextBox1 and display "That path exists already.". Otherwise, it will create a New Folder saved in the Directory and Folder name that corresponds to TextBox1. It will also clear the value of the TextBox1 and display "Folder Is Created.......!".
Now, try to type this on your TextBox1: C:/Sourcecodester Tutorials. Then Click Button1. This will display the result like the image below:
Then, try to look at your C Directory. It has now a folder named Sourcecodester Tutorials.
Download the source code below and try it! :)
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
STI College - Surigao City
Follow and add me in my Facebook Account: https://www.facebook.com/donzzsky