multiple settings files

M

michael sorens

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?
 
F

Family Tree Mike

michael sorens said:
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.
 
S

Steven Cheng

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/embeddedresources.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:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#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/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.



--------------------
 
M

michael sorens

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.)
 
S

Steven Cheng

Thanks for your reply Michael,

I'm glad that you've managed to work out the solution based on the
information. Also, in .NET there are two kind of resource(can be embeded in
assembly).

One is the pure assembly binary resource(which you use).

Another is the culture/multi-lingual specific resource(can be embeded based
on different culture/language).

If you have any further questions or need any further help, always welcome
to post here.

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:
(e-mail address removed).




--------------------
From: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= <[email protected]>
References: <[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top