Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / February 2005

Tip: Looking for answers? Try searching our database.

app.config

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bragadiru - 20 Aug 2003 15:14 GMT
I have a solution with 2 projects: a class library(my.dll) + a windows
application (mine.exe). In exe project I have a reference to the dll. In
both I have app.config files, BUT only mine.exe.config file is generated in
\bin\Debug\ folder of exe app. What can I do to generate my.dll.config from
app.config ?

Thnx for any advice.
Rajasi Saha [MS] - 21 Aug 2003 01:28 GMT
The app.config file is associated only with an exe, not a dll, so you cannot
have a your.dll.config.
However, from within the dll, you can access settings in app.exe.config.

rajasi

> I have a solution with 2 projects: a class library(my.dll) + a windows
> application (mine.exe). In exe project I have a reference to the dll. In
[quoted text clipped - 3 lines]
>
> Thnx for any advice.
Joeri De Valck - 22 Aug 2003 20:33 GMT
I created this class which lets you create a kind of app.config for dll's
Imports System.Xml

Imports System.Configuration

' usage:

' The xml file must be built like this

'<configuration>

' <assemblySettings>

' <add key="key1" value="Value for key1 (OtherTestLib)"/>

' <add key="key2" value="Value for key2 (OtherTestLib)"/>

' </assemblySettings>

'</configuration>

' Dim settings as AssemblySetting(filename)

' Dim var1 as string = settings("key1")

' Dim var2 as string = settings("key2")

' for enumeration

' Dim settings as IDictionary

' Dim entry as DictionaryEntry

'

' settings = AssemblySetting.GetConfig(filename)

' For Each entry in settings

'

' Next

Public Class AssemblySettings

Private mysettings As IDictionary

Dim entry As DictionaryEntry

Public Sub New(ByVal FileName As String)

mysettings = GetConfig(FileName)

End Sub

Default Public ReadOnly Property KeyValue(ByVal KeyName As String) As String

Get

Dim retVal As Object

If Not mysettings Is Nothing Then

retVal = mysettings(KeyName)

End If

If Not retVal Is Nothing Then

Return CType(retVal, String)

Else

Return ""

End If

End Get

End Property

Shared Function GetConfig(ByVal FileName As String) As IDictionary

Dim doc As XmlDocument = New XmlDocument()

Dim nodes As XmlNodeList

Dim node As XmlNode

doc.Load(FileName)

nodes = doc.GetElementsByTagName("assemblySettings")

For Each node In nodes

If node.LocalName = "assemblySettings" Then Return CType(New
DictionarySectionHandler().Create(Nothing, Nothing, node), IDictionary)

Next

End Function

End Class

> I have a solution with 2 projects: a class library(my.dll) + a windows
> application (mine.exe). In exe project I have a reference to the dll. In
[quoted text clipped - 3 lines]
>
> Thnx for any advice.
chris yoker - 21 Feb 2005 15:12 GMT
hiya,
good solution :-)

I am wondering though, when you call
"GetConfig(ByVal fileName As String) As IDictionary"

..did you have to hard-code the fileName?
Is there a way that I could obtain the filePath without hard-coding?

eg, I know that I can use things like " Application.ExecutablePath" to get
the path of the EXE, but I am obviously using a class library that launches
the EXE, so myClassLibrary:

1) starts the EXE as an external program
2) has the same output path as that of the EXE.

Do I have to hard-code the path of the fileName, or can I use an
"application property" or something siliar, so that I don't have to hard-
code?

make sense?

cheers,
yogi

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.