Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to create, move and delete directory and validate existence of directory using System.IO namespace in VB.Net.
Download Source Code : 1425_SearchInGridView.zip

System.IO namespace provides methods to deal with the files and directories. Following code shows you how to manipulate directories in Visual Basic.Net using System.IO namespace.

Create New Directory

Imports System

Imports System.IO

Module Module1

 

  Sub Main()

    CreateDirectory()

  End Sub

  Sub CreateDirectory()

    Dim Path As String

    Path = "D:\MyworkFolder"

    Directory.CreateDirectory(Path)

  End Sub

End Module

 

Validate before Creating New Directory

 

Imports System

Imports System.IO

Module Module1

 

  Sub Main()

    CreateDirectory()

  End Sub

 

  Sub CreateDirectory()

    Dim Path As String

    Path = "D:\MyworkFolder"

    Try

 

      If Directory.Exists(Path) Then

        Console.Write("This Folder already Exist")

      Else

        Directory.CreateDirectory(Path)

      End If

    Catch ex As Exception

      Console.Write(ex.ToString)

    End Try

 

  End Sub

End Module

 

Move Directory

Imports System

Imports System.IO

Module Module1

 

  Sub Main()

    CreateDirectory()

  End Sub

  Sub CreateDirectory()

    Dim PathToMove As String

    PathToMove = "D:\MyworkFolder"

    Dim Destination As String

    Destination = "D:\Bilal\MyworkFolder"

    Try

 

      If Directory.Exists(PathToMove) Then

        Directory.Move(PathToMove, Destination)

      Else

        Console.Write("There is No such Directory to move")

      End If

    Catch ex As Exception

      Console.Write(ex.ToString)

    End Try

  End Sub

End Module

 

Move Directory

Imports System

Imports System.IO

Module Module1

 

  Sub Main()

    CreateDirectory()

  End Sub

  Sub CreateDirectory()

    Dim Path As String

    Path = "D:\MyworkFolder"

    Try

 

      If Directory.Exists(Path) Then

        Directory.Delete(Path)

      Else

        Console.Write("There is No such Directory to Delete")

      End If

    Catch ex As Exception

      Console.Write(ex.ToString)

    End Try

  End Sub

End Module
Article Comments
This artical is very good and helpful for me..

Thank You !

Posted on 4/2/2007 6:00:22 AM by Ashish Chavan

easily understandable,nice and useful.

Thank you.

Posted on 1/2/2008 11:21:19 PM by B.Guru murthy

It is a good article.

It explains in brief about basic directory handling.

Posted on 1/21/2008 11:15:01 PM by Varun Patel

thanks for your help

Posted on 8/24/2008 9:01:39 PM by yogesh

Thanks, Easy and Useful

Posted on 11/11/2009 2:10:02 AM by Sunil

Thank you. Very helpful

Posted on 4/21/2010 7:45:54 PM by OD

Thanks a lot. Greatly appreciate it. Very Helpful,

Posted on 6/16/2010 2:42:08 PM by Archana Parikh

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to convert an Excel file to CSV format using VB.Net, ASP.Net.

Disclaimer - Privacy
© 2002-2017 DevASP.net