Wednesday, 10 February 2016

How to Check if a Folder Exists in Vb.NetIn Feburary 2016 10,

In Feburary 2016 10,
Type 'Dim pathName As String' in your VB.NET code to define a string variable to hold the path to the folder that you want to look for. This string variable is called 'pathName.' As an example, set the value of the string variable 'pathName' to 'C:\TestFolder.' This can be implemented using the following code; 'pathName = 'C:\TestFolder'.'
Type 'Imports System.IO' in the first line of your code page to import the 'System.IO' library into your VB.net code. The 'System.IO' is a .NET framework class library that is available to all .NET based code. As the code is being developed in VB.NET, this library is also automatically available for use to the developer. A class library is a collection of classes with various functions that programmers can use in their software applications.The 'DirectoryInfo' class is a part of the 'System.IO' class library that exposes functions for creating and moving through directories and sub-directories.
Type the line 'Directory.Exists(pathName)' to use the 'Exists' function of the 'DirectoryInfo class' to check if the 'C:\TestFolder' folder exists on your computer. The 'Exists' function will return a true boolean value if the folder exists, and it will return a false boolean value if the folder does not exist. To catch this boolean value, define a boolean variable by using the following code line: 'Dim answer As Boolean.' Use this 'answer' variable to accept the return value of the 'Exists' function by using the following code line: ' answer = Directory.Exists(pathName).'
Build and compile your code by clicking on the 'Project' option on the top tool bar and then clicking on 'Build.' Execute the code by clicking on the 'Debug' option on the top tool bar and then clicking 'Run.' The VB.net code will execute, check if the 'C:\TestFolder' exists on your computer and return an appropriate true or false value.
In Feburary 2016 10,

No comments:

Post a Comment