• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 442
  • Last Modified:

Console application using config file data

Hi, I have a simple console application that has been set to copy everything from one location to two others...

my issue is the networked location at 4 sites may be different. A program that is already in place has a config file which I would like to 'tap' into and use part of the settings to determine the network write location at that particular site.

the config file is currently in a location of c:\iwb\config\user.config

Please see the code below...

The particular aspect I am interested in in my application is this

            <setting name="IWB_DesignatedShared_Folder" serializeAs="String">
                <value>T:\KENN\</value>
            </setting>

the location is going to change but is user defined by the other app.

The other code is my entire console app. If anyone can help me with the network write to the location determined by the config file I would be eternally grateful.

Thank you

Simon

XML from the config file

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="IWBSettingsEx.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
            <section name="IWBSettingsEx.IwbLocalSettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <userSettings>
        <IWBSettingsEx.Properties.Settings>
            <setting name="Factory_Number" serializeAs="String">
                <value>17</value>
            </setting>
            <setting name="Factory_Name" serializeAs="String">
                <value>Wissington</value>
            </setting>
            <setting name="IWB_LocalWeighings_Folder" serializeAs="String">
                <value>C:\IWB\</value>
            </setting>
            <setting name="IWB_LocalExternal_Folder" serializeAs="String">
                <value>C:\Temp\Kenn\Csv\</value>
            </setting>
            <setting name="IWB_DesignatedShared_Folder" serializeAs="String">
                <value>T:\KENN\</value>
            </setting>
            <setting name="IWB_DB" serializeAs="String">
                <value>peiwb</value>
            </setting>
            <setting name="NR_BRIDGES" serializeAs="String">
                <value>2</value>
            </setting>
            <setting name="PC_IDENTITY" serializeAs="String">
                <value>WIDEV1</value>
            </setting>
            <setting name="PRT_PAGE" serializeAs="String">
                <value>FULL</value>
            </setting>
            <setting name="BIC_DB" serializeAs="String">
                <value>pebic</value>
            </setting>
            <setting name="OWB_DEVICE" serializeAs="String">
                <value>NEDAP</value>
            </setting>
            <setting name="STATION_ID" serializeAs="String">
                <value>01AUTO</value>
            </setting>
            <setting name="CROP_DB" serializeAs="String">
                <value>CTSDEVCO</value>
            </setting>
            <setting name="CROP_USER" serializeAs="String">
                <value>CTSDEVCO</value>
            </setting>
            <setting name="CROP_PASS" serializeAs="String">
                <value>CTSDEVCO</value>
            </setting>
            <setting name="ErrLogLocation" serializeAs="String">
                <value>F:\IWBERROR\</value>
            </setting>
            <setting name="DrvsScrFont" serializeAs="String">
                <value>Arial, 24pt, style=Bold</value>
            </setting>
            <setting name="DrvsScrBackGndColor" serializeAs="String">
                <value>0, 0, 64</value>
            </setting>
            <setting name="DrvScrFontColor" serializeAs="String">
                <value>Yellow</value>
            </setting>
            <setting name="DrvScrFontSec" serializeAs="String">
                <value>Arial, 21.75pt, style=Bold</value>
            </setting>
            <setting name="DrvScrFontColorSec" serializeAs="String">
                <value>Olive</value>
            </setting>
            <setting name="DrvScrFacMsgsFont" serializeAs="String">
                <value>Arial, 21.75pt, style=Bold</value>
            </setting>
            <setting name="DrvScrFacMsgsFontColor" serializeAs="String">
                <value>White</value>
            </setting>
        </IWBSettingsEx.Properties.Settings>
        <IWBSettingsEx.IwbLocalSettings>
            <setting name="DrvScrFontColorSec" serializeAs="String">
                <value>Red</value>
            </setting>
            <setting name="DrvScrFontNameSec" serializeAs="String">
                <value>Microsoft Sans Serif, 8.25pt, style=Bold</value>
            </setting>
            <setting name="DrvsScrFontName" serializeAs="String">
                <value>Arial, 24pt, style=Bold</value>
            </setting>
            <setting name="DrvsScrBackGndColor" serializeAs="String">
                <value>0, 0, 64</value>
            </setting>
            <setting name="DrvScrFontColor" serializeAs="String">
                <value>Yellow</value>
            </setting>
            <setting name="DrvScrFacMsgsFontColor" serializeAs="String">
                <value>White</value>
            </setting>
            <setting name="DrvScrFacMsgsFont" serializeAs="String">
                <value>Arial, 21.75pt, style=Bold</value>
            </setting>
        </IWBSettingsEx.IwbLocalSettings>
    </userSettings>
</configuration>

Open in new window

Imports System.IO.DriveType
Imports System.IO

''' <summary>
''' 
''' Console Application created by Simon Price as part of the IWB Refresh Project.
'''  
''' Sub Main - Calls each Minor Sub beneath it to copy files from local drive to 
''' both network and USB ttached Device (UAD).
''' 
''' local_copy - This copies files from c:\IWB\Beet-Tally-Files-Local to 
''' c:\IWB\Beet-Tally-Files-USB
''' 
''' directory_create - This checks the network is available and then looks at the 
''' UserID of the logged on user and creates a new folder if one does not 
''' already exist in their name and then calls Network_Copy ()
''' 
''' network_copy - This again looks at the network availability and then copies the files
''' from c:\IWB\Beet-Tally-Files-Local to f:\IWB\Beet-Tally-Files-Net
''' 
''' attached_device_copy - This enumerates through the the available drives looking for 
''' IO.DriveType.Removable. A Drive letter has specifically not been assigned to this area 
''' as we cannot with 100% certainty say that it will always be assigned the same drive 
''' letter.  Once it has found the removable media it will then copy the files from the last
''' seven days to the the UAD. 
''' 
''' </summary>
''' <remarks></remarks>

Module Module1

    Const srcDirLocal = "c:\IWB\Beet-Tally-Files-Local"
    Const destDirLocal = "c:\IWB\Beet-Tally-Files-USB"
    Const destDirnetwork = "f:\IWB\Beet-Tally-Files-Net"


    Sub Main()

        local_copy()
        directory_create()
        'network_copy()
        attached_device_copy()

    End Sub

    Sub local_copy()

        Dim hourAgo As DateTime
        hourAgo = DateAdd("D", -7, Now)

        Dim fso As Object
        fso = CreateObject("Scripting.FileSystemObject")

        'Local file copy                        
        For Each f In fso.GetFolder(srcDirLocal).Files
            f.Copy(destDirLocal & "\")
        Next 'f

    End Sub

    Sub network_copy()

        Dim hourAgo As DateTime
        hourAgo = DateAdd("D", -7, Now)

        Dim fso As Object
        fso = CreateObject("Scripting.FileSystemObject")

        If System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable = True Then
            'Network file copy
            For Each f In fso.GetFolder(srcDirLocal).Files

                f.Copy(destDirnetwork & "\" & Environment.UserName & "\")
            Next 'f

        Else
            Exit Sub
        End If

    End Sub

    Sub attached_device_copy()

        For Each drive As System.IO.DriveInfo In System.IO.DriveInfo.GetDrives
            If drive.DriveType = IO.DriveType.Removable AndAlso drive.IsReady Then

                Dim DriveLetter As String = drive.Name
                Dim PathToUSBDrive = DriveLetter & IO.Path.GetFileName(destDirLocal)

                Dim hourAgo As DateTime
                hourAgo = DateAdd("D", -7, Now)

                Dim fso As Object
                fso = CreateObject("Scripting.FileSystemObject")

                'Local file copy                        
                For Each f In fso.GetFolder(srcDirLocal).Files
                    f.Copy(PathToUSBDrive & "\")

                Next 'f

            End If
        Next

    End Sub

    Sub directory_create()

        If System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable = True Then

            If (Directory.Exists(destDirnetwork & "\" & Environment.UserName)) = True Then
                network_copy()
            Else
                Directory.CreateDirectory(destDirnetwork & "\" & Environment.UserName & "\")
                network_copy()
            End If

        Else
            Exit Sub
        End If

    End Sub

End Module

Open in new window

0
SimonPrice33
Asked:
SimonPrice33
1 Solution
 
CodeCruiserCommented:
You mean the location is in config file of another program? Try parsing the xml

http://www.codeproject.com/KB/cpp/parsefilecode.aspx
0
 
SimonPrice33Author Commented:
Yes, thats what I mean. I will try parsing the xml and will let you know how i get on.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now