XDASrv Reference Manual
Read AppSettings
Send comments on this topic.
Samples > Read AppSettings

Glossary Item Box

ReadAppConfiguation Method
Sample method that shows how configuration definitions can be read from the application configuration file web.config or xxxx.EXE.CONFIG for a command line or Windows Forms application.
See the sample configuration file for the definition syntax. The configuration file has to be in the same directory the web service asmx/svc file respectively the  the EXE file.



C# sample code
using System;
using System.Configuration;
using System.Threading;

namespace NetDriver
{
   public class OPCNetDriver : OPCNetInterface
   {
      public string ReadAppConfiguation( string name )
      {
         object val;
         try
         {
            AppSettingsReader ar = new AppSettingsReader();
            string str = "";
            val = ar.GetValue( name, str.GetType() );
            ar = null;
         }
         catch             // file or definition not found
         {
            val = "1" ;   // use default value
         }
         return val.ToString() ;
      }
        
   }
}


VB sample code
<System.Runtime.InteropServices.ProgId("NetDriver.OPCNetDriver")> Public Class OPCNetDriver
    Public Function ReadAppConfiguation(ByVal name As String) As String

        Dim dval As Object
        Try
            Dim ar As System.Configuration.AppSettingsReader
            ar = New System.Configuration.AppSettingsReader()
            Dim str As String = ""
            dval = ar.GetValue(name, str.GetType())
            ar = Nothing        ' release object
        Catch  ' file or definition not found
            dval = "1"   ' use default value
        End Try
        Return dval.ToString()

    End Function
End Class
Copyright © 2002-2011 Advosol Inc. All Rights Reserved.