CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2012
    Posts
    4

    vb.net 2010 edit on looking for valid directory path

    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.

    Code:
    #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 the directory path of: https://msdn.microsoft.com/en-us/lib...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:

    Code:
    #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
    Last edited by HanneSThEGreaT; June 22nd, 2015 at 03:03 PM. Reason: added code tags

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: vb.net 2010 edit on looking for valid directory path

    You cannot have an IF function inside a config file, as it is merely XML. You will have to read the path from your config file, check if the path is valid ( from your form ) based on that, display the appropriate form. You could even check the validity inside the New Constructor of your form you'd like to show.

    PS, please remember Code tags next time

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured