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: designer 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
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]

Visit and like my page on Facebook at: Bermz ISware Solutions

Subscribe at my YouTube Channel at: SerBermz

Add new comment