Results 1 to 10 of 10

Thread: No app.config on a PPC?

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    No app.config on a PPC?

    Seems like there is no place in the framework for application settings on a PPC app using VS2005.

    I'm about to develop my own class to handle this - writing a .ini file - yuk...

    Has anyone overcome this with a better method - registry like - or something like that?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: No app.config on a PPC?

    Hi,
    I just use an XML file and have routines to read and write.
    Format is
    <BackupTo>SD Card</BackupTo>
    etc.

    Peter Foot (www.inthehand.com) has a library that supports app.config, plus many other facilities


    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  3. #3

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: No app.config on a PPC?

    Thanks - well since I have to read and write this file myself I mine as well use XML.

    Are there XML classes in VS 2005? I only have two or three values to store - so I certainly can do the parsing myself.

    Where do you store the .XML file?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: No app.config on a PPC?

    Hi,
    I store the XML file in the same folder as the program.
    Code as below, used like....

    Dim path as string = Get_From_Config_File("PPC_Folder")

    vb Code:
    1. Public Function Get_From_Config_File(ByVal strEle As String) As String
    2.         Current_Position("Get_From_Config_File " & strEle)
    3.         Dim dr As XmlTextReader
    4.         'Dim appPath As String
    5.         'appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
    6.         Dim fs As FileStream = New FileStream(Path.Combine(DataPath, "Config.xml"), FileMode.Open)
    7.         Dim strRet As String
    8.         dr = New XmlTextReader(fs)
    9.         While dr.Read
    10.             If dr.NodeType = XmlNodeType.Element And dr.Name = strEle Then
    11.                 strRet = dr.ReadElementString()
    12.                 dr.Close()
    13.                 fs.Close()
    14.                 Return strRet
    15.             End If
    16.         End While
    17.         dr.Close()
    18.         fs.Close()
    19.  
    20.     End Function
    21.     Public Function Write_To_Config_File(ByVal strEle As String, ByVal strVal As String) As String
    22.         Current_Position("Write_To_Config_File")
    23.  
    24.         Dim iCt As Integer
    25.         Dim bDone As Boolean
    26.         'Dim appPath As String
    27.         'appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
    28.         Dim xd As XmlDocument = New XmlDocument
    29.         xd.Load(Path.Combine(DataPath, "Config.xml"))
    30.         Dim xe As XmlElement = xd.DocumentElement
    31.         If xe.Name = "Configuration_Data" Then
    32.             For Each xce As XmlElement In xe.ChildNodes
    33.                 If xce.ChildNodes.Count = 1 Then
    34.                     If xce.Name = strEle Then
    35.                         xce.FirstChild.Value = strVal
    36.                         bDone = True
    37.                     End If
    38.                 Else
    39.                     For iCt = 0 To xce.ChildNodes.Count - 1
    40.                         If xce.ChildNodes(iCt).Name = strEle Then
    41.                             xce.ChildNodes(iCt).FirstChild.Value = strVal
    42.                             bDone = True
    43.                         End If
    44.                     Next
    45.                 End If
    46.                 If bDone Then
    47.                     Exit For
    48.                 End If
    49.             Next
    50.         End If
    51.         '    write the document back to disk
    52.         xd.Save(Path.Combine(DataPath, "Config.xml"))
    53.  
    54.     End Function

    HTH

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  5. #5
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: No app.config on a PPC?

    Hi,
    sample config file is...

    <Configuration_Data>

    <Device>XDA</Device>
    <Distance>250</Distance>
    <Time>30</Time>
    <AllowExit>Y</AllowExit>
    </Configuration_Data>

    etc etc

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  6. #6

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: No app.config on a PPC?

    Thank you - thank you - so very much.

    That would have taken me an hour of reading through the VS doc to find all that code!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: No app.config on a PPC?

    Hi,
    just realised, you will have to remove the 'current position' stuff, and work out your path, but apart from that you should be good to go

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  8. #8

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: No app.config on a PPC?

    I've been using \My Documents\Business\APC as a folder - APC being the name of the APP.

    Is it more appropriate to bury this in program file somewhere??

    What the standard on a PPC?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: No app.config on a PPC?

    Hi,
    \Program Files\Company-Prod Name\
    then your programs.

    That is where it will go if you build a deployment package

    Pete
    Pete Vickers
    MVP - Device Application Development
    http://www.gui-innovations.com http://mobileworld.appamundi.com/blogs/

  10. #10

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: No app.config on a PPC?

    I don't do a lot of VS work yet - but I took your sample and wrapped it up in a class and also added support for creating the CONFIG.XML file and also adding new nodes to it.

    If you see any poor-VS code please comment!

    vb Code:
    1. Imports System
    2. Imports System.IO
    3. Imports System.Xml
    4.  
    5. Public Class Settings
    6.  
    7.     Private strServer As String
    8.     Private strUserId As String
    9.     Const Datapath = "\Program Files\APC"
    10.  
    11.     Public Property sServer() As String
    12.         Get
    13.             Return strServer
    14.         End Get
    15.         Set(ByVal value As String)
    16.             strServer = Write_To_Config_File("Server", value)
    17.         End Set
    18.     End Property
    19.  
    20.     Public Property sUserId() As String
    21.         Get
    22.             Return strUserId
    23.         End Get
    24.         Set(ByVal value As String)
    25.             strUserId = Write_To_Config_File("UserId", value)
    26.         End Set
    27.     End Property
    28.  
    29.     Public Sub New()
    30.         strServer = Get_From_Config_File("Server")
    31.         strUserId = Get_From_Config_File("UserId")
    32.     End Sub
    33.  
    34.     Public Function Get_From_Config_File(ByVal strEle As String) As String
    35.         Try
    36.             Dim dr As XmlTextReader
    37.             Dim fs As FileStream = New FileStream(Path.Combine(Datapath, "Config.xml"), FileMode.Open)
    38.             Dim strRet As String
    39.             strRet = ""
    40.             dr = New XmlTextReader(fs)
    41.             While dr.Read
    42.                 If dr.NodeType = XmlNodeType.Element And dr.Name = strEle Then
    43.                     strRet = dr.ReadElementString()
    44.                     dr.Close()
    45.                     fs.Close()
    46.                 End If
    47.             End While
    48.             dr.Close()
    49.             fs.Close()
    50.             Return strRet
    51.         Catch ex As FileNotFoundException
    52.             Using sw As StreamWriter = New StreamWriter(Path.Combine(Datapath, "Config.xml"))
    53.                 sw.WriteLine("<Configuration_Data>")
    54.                 sw.WriteLine("</Configuration_Data>")
    55.                 sw.Close()
    56.             End Using
    57.             Return ""
    58.         Catch ex As Exception
    59.             Return ""
    60.         End Try
    61.     End Function
    62.  
    63.     Public Function Write_To_Config_File(ByVal strEle As String, ByVal strVal As String) As String
    64.         Write_To_Config_File = ""
    65.         Dim iCt As Integer
    66.         Dim bDone As Boolean
    67.         'Dim appPath As String
    68.         'appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
    69.         Dim xd As XmlDocument = New XmlDocument
    70.         xd.Load(Path.Combine(Datapath, "Config.xml"))
    71.         Dim xe As XmlElement = xd.DocumentElement
    72.         If xe.Name = "Configuration_Data" Then
    73.             For Each xce As XmlElement In xe.ChildNodes
    74.                 If xce.ChildNodes.Count = 1 Then
    75.                     If xce.Name = strEle Then
    76.                         xce.FirstChild.Value = strVal
    77.                         bDone = True
    78.                     End If
    79.                 Else
    80.                     For iCt = 0 To xce.ChildNodes.Count - 1
    81.                         If xce.ChildNodes(iCt).Name = strEle Then
    82.                             xce.ChildNodes(iCt).FirstChild.Value = strVal
    83.                             bDone = True
    84.                         End If
    85.                     Next
    86.                 End If
    87.                 If bDone Then
    88.                     Exit For
    89.                 End If
    90.             Next
    91.             If Not bDone Then
    92.                 Dim elem As XmlElement = xd.CreateElement(strEle)
    93.                 elem.InnerText = strVal
    94.                 xe.AppendChild(elem)
    95.             End If
    96.         End If
    97.         '    write the document back to disk
    98.         xd.Save(Path.Combine(Datapath, "Config.xml"))
    99.         Write_To_Config_File = strVal
    100.     End Function
    101. End Class

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

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