|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Read From Application Config File In Class LibraryI have read many posts on how you cannot have an app.config file for a class
library, but must read from the main application. This URL, #3, highlights this point: http://www.grimes.demon.co.uk/dotnet/configFAQ.htm#005 I cannot simply get an answer as to how to read from the applications main app.config file. Null exception errors are the result. Does anybody have actual code that has done this. Also reading from web.config would be great. Hello Derek,
> I have read many posts on how you cannot have an app.config file for a Could you post which values you have stored in which config file, and how > class library, but must read from the main application. This URL, #3, > highlights this point: > > http://www.grimes.demon.co.uk/dotnet/configFAQ.htm#005 > > I cannot simply get an answer as to how to read from the applications > main app.config file. Null exception errors are the result. Does > anybody have actual code that has done this. Also reading from > web.config would be great. you're reading them from your code. This should be very straightforward. ConfigurationManager.AppSettings["Name"] (see: http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings%28VS.80%29.aspx) should do the trick. If you've stored the data in a custom section it would be a little more work. If youw ant to read from a specific config file you can use ConfigurationManager.Open***Configuration() (See: http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager_methods%28VS.80%29.aspx) -- Jesse Houwing jesse.houwing at sogeti.nl Forget to mention that I am doing this at design time with design time
controls. Cannot get it working. Trying to read from either app.config or web.config in the main program FROM my class library. Lots of articles on the web say you can't. If you have specifically done this, I would very much appreciate knowing how. Show quoteHide quote "Jesse Houwing" <jesse.houwing@newsgroup.nospam> wrote in message news:e5317a7e7800ea988cbb84a8613611a@news.microsoft.com... > Hello Derek, > >> I have read many posts on how you cannot have an app.config file for a >> class library, but must read from the main application. This URL, #3, >> highlights this point: >> >> http://www.grimes.demon.co.uk/dotnet/configFAQ.htm#005 >> >> I cannot simply get an answer as to how to read from the applications >> main app.config file. Null exception errors are the result. Does >> anybody have actual code that has done this. Also reading from >> web.config would be great. > > Could you post which values you have stored in which config file, and how > you're reading them from your code. This should be very straightforward. > > ConfigurationManager.AppSettings["Name"] > (see: > http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings%28VS.80%29.aspx) > > should do the trick. > > If you've stored the data in a custom section it would be a little more > work. > > If youw ant to read from a specific config file you can use > > ConfigurationManager.Open***Configuration() > (See: > http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager_methods%28VS.80%29.aspx) > > -- > Jesse Houwing > jesse.houwing at sogeti.nl > > Hello Derek,
> Forget to mention that I am doing this at design time with design time Reading from the config @ design time is indeed not supported. I know that > controls. Cannot get it working. Trying to read from either app.config > or web.config in the main program FROM my class library. Lots of > articles on the web say you can't. If you have specifically done this, > I would very much appreciate knowing how. the guy behind Peter's Data Package used to provide a library that sits inside Visual Studio that can do this. You might want to check out his producs and see what they can do for you. If you wan to acchieve this yourself, you need to install the Visual Studio SDK and dive into VSIP. It's not pretty if you need to go that way. You could also have a look at DXCore by DevExpress, I'm not sure, but my guess is that you could do what you want using their product in an easier way than through VSIP directly. DevExpress has a very active forum and very good support, they can probably help you out, or tell you to stop right now ;). http://www.peterblum.com/ http://www.devexpress.com/ Jesse Show quoteHide quote > "Jesse Houwing" <jesse.houwing@newsgroup.nospam> wrote in message jesse.houwing at sogeti.nl> news:e5317a7e7800ea988cbb84a8613611a@news.microsoft.com... > >> Hello Derek, >> >>> I have read many posts on how you cannot have an app.config file for >>> a class library, but must read from the main application. This URL, >>> #3, highlights this point: >>> >>> http://www.grimes.demon.co.uk/dotnet/configFAQ.htm#005 >>> >>> I cannot simply get an answer as to how to read from the >>> applications main app.config file. Null exception errors are the >>> result. Does anybody have actual code that has done this. Also >>> reading from web.config would be great. >>> >> Could you post which values you have stored in which config file, and >> how you're reading them from your code. This should be very >> straightforward. >> >> ConfigurationManager.AppSettings["Name"] >> (see: >> http://msdn.microsoft.com/en-us/library/system.configuration.configur >> ationmanager.appsettings%28VS.80%29.aspx) >> should do the trick. >> >> If you've stored the data in a custom section it would be a little >> more work. >> >> If youw ant to read from a specific config file you can use >> >> ConfigurationManager.Open***Configuration() >> (See: >> http://msdn.microsoft.com/en-us/library/system.configuration.configur >> ationmanager_methods%28VS.80%29.aspx) >> -- >> Jesse Houwing >> jesse.houwing at sogeti.nl -- Jesse Houwing
Other interesting topics
Design Time Controls
Cannot use Mustinherit in a base form object properties presentation flicker when restraining one form to only move within the bounds of another System.Windows.Forms.Control.Handle==HWND? Saving and retrieving WinForm template info Project consisting of multiple projects Validating Event Bug Win forms designer - controlling the designer code generation What control did Microsoft Use? |
|||||||||||||||||||||||