By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,022 Members | 856 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,022 IT Pros & Developers. It's quick & easy.

multiple settings files

P: n/a
I have created a class library (DLL) that requires a certain XML file in the
same directory as the DLL. This XML file is essentially a configuration or
settings file but I want it to be a separate file from the standard
user.config file. My attempts to do this did not yield what I needed:

(1) I first thought of just using a separate Settings object in my project,
but I observed that that simply inserts a separate section in user.config,
not a separate file as I require.

(2) I next tried just a plain XML file that I could read/write manually. I
could then add a post-build command to copy this file to the bin directory
when I create my DLL. That's fine for building the library itself but if I
add this library into another project as a reference how could I
automatically bring the XML file along as well?

Is there a different (better?) way to do something like this?

Nov 20 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"michael sorens" <m_********@newsgroup.nospamwrote in message
news:F3**********************************@microsof t.com...
>I have created a class library (DLL) that requires a certain XML file in
the
same directory as the DLL. This XML file is essentially a configuration or
settings file but I want it to be a separate file from the standard
user.config file. My attempts to do this did not yield what I needed:

(1) I first thought of just using a separate Settings object in my
project,
but I observed that that simply inserts a separate section in user.config,
not a separate file as I require.

(2) I next tried just a plain XML file that I could read/write manually. I
could then add a post-build command to copy this file to the bin directory
when I create my DLL. That's fine for building the library itself but if I
add this library into another project as a reference how could I
automatically bring the XML file along as well?

Is there a different (better?) way to do something like this?

With option (2) have you tried to test the existence of the file, and if it
does not exist, simply create it with defaults? When your dll first needs
it, it could request the user to setup some settings. With this approach,
the client to your dll could either not create the file, or somehow setup
one where it installs your dll.

Nov 20 '08 #2

P: n/a
Hi Michael,

As for the scenario you mentioned, I think the best approach is storing the
data into the built-in configuration section(such as AppSetting or a custom
config section). Thus, you can use .NET standard configuration API to load
it.

Since you want to separate the file, you can consider Mike's suggestion
about define a internal method which can programmtically generate a default
template(of that xml file). Thus, if the target application hasn't copied
the XML file(together with the dll), your internal method will autogenerate
one. For the template xml file, you can consider storing it in
dll/assembly's embeded resource:

#Understanding Embedded Resources in Visual Studio .NET
http://www.codeproject.com/KB/dotnet...resources.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subs.../aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= <m_********@newsgroup.nospam>
Subject: multiple settings files
Date: Wed, 19 Nov 2008 19:38:00 -0800
>
I have created a class library (DLL) that requires a certain XML file in
the
>same directory as the DLL. This XML file is essentially a configuration or
settings file but I want it to be a separate file from the standard
user.config file. My attempts to do this did not yield what I needed:

(1) I first thought of just using a separate Settings object in my
project,
>but I observed that that simply inserts a separate section in user.config,
not a separate file as I require.

(2) I next tried just a plain XML file that I could read/write manually. I
could then add a post-build command to copy this file to the bin directory
when I create my DLL. That's fine for building the library itself but if I
add this library into another project as a reference how could I
automatically bring the XML file along as well?

Is there a different (better?) way to do something like this?

Nov 20 '08 #3

P: n/a
Thanks to your pointers I discovered that embedded resources is the key to
what I need. I added my file as a resource, then during startup I check for
its existence as a file and create the file from the resource if it is not
already there.
(I found this additional link on Adding and Editing Resources most useful:
http://msdn.microsoft.com/en-us/library/7k989cfy.aspx.)

Nov 21 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.