dc

dc

  • NA
  • 663
  • 0

vb.net 2010 edit on looking for valid directory path

Jun 15 2015 5:35 PM

In an existing vb.net 2010 desktop application, I want to remove the hardcoded directory paths that are contained within the entire application and obtain the values from a app.config file instead. Right now in the Global.vb program, I have the following code and it works fine as long as the directory path supplied in the app.config file is correct.

#Region "Oledb Connect"
 Imports System
 Imports System.Collections.Generic
 Imports System.IO.Path
 Imports System.Configuration.ConfigurationManager
 #End Region

Module [Global]
     Public _strDirectoryPath As String = ConfigurationManager.AppSettings("File_directory_path")
     Public dirAccessFiles As String() = Directory.GetFiles(_strDirectoryPath, "*.accdb")
 End Module

However when there is an error, I have a coding problem. I basically want to check to see if the directory file exists before startup form is loaded. I want to have an if test 'like' what is located in:  https://msdn.microsoft.com/en-us/library/system.io.directory.exists(v=vs.110).aspx, but the global.vb program will not allow me to have an 'if' test coded. Thus can you tell me what I can do to be able to add the if test to see if the directory exists?

Here is the code from the startup project file if it helps to explain what else I need to change:
 #Region " Global Form "
 
     Private Shared m_GlobalForm As frmMain
     Public Shared Property GlobalForm() As frmMain
         Get
             If m_GlobalForm Is Nothing OrElse m_GlobalForm.IsDisposed Then
                 m_GlobalForm = New frmMain
             End If
         Return m_GlobalForm
         End Get
         Set(ByVal Value As frmMain)
             m_GlobalForm = Value
         End Set
     End Property
 #End Region
    
     Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         frmMain.GlobalForm = Me
     End Sub


Answers (1)