Create Folder using VB.NET

Submitted by: 
Visitors have accessed this post 1423 times.

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:

  1. Dim di As DirectoryInfo = New DirectoryInfo(TextBox1.Text)
  2. If di.Exists Then
  3. MsgBox("That path exists already.")
  4. TextBox1.Clear()
  5. Else
  6. di.Create()
  7. MsgBox("Folder Is Created.......!", MsgBoxStyle.Information)
  8. TextBox1.Clear()
  9. 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:

Create New Folder

Then, try to look at your C Directory. It has now a folder named Sourcecodester Tutorials.

Create Folder

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.

Best Regards,

Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
STI College - Surigao City
Mobile: 09488225971
E-mail:[email protected]

Follow and add me in my Facebook Account:

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.