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 / .NET Framework / New Users / April 2006

Tip: Looking for answers? Try searching our database.

app.config files and MMC snap-in

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
richlm - 31 Mar 2006 13:12 GMT
I'm developing a snap-in for MMC 3.0 using .Net framework 2.0 and the new
MMC class library.

I need to store some configuration settings, ideally in a .config file
associated with my snap-in dll.

A couple of possible solutions:
1. Deploy an mmc.exe.config to %windir%\System32 - not really a workable
solution.

2. Open a configuration file explicitly as a "Configuration" instance using
e.g. ConfigurationManager.OpenMappedExeConfiguration. That's almost OK - but
the config file either needs to be in System32 or we have to hard-code a
path (or maybe get the path from Assembly.CodeBase).

The same issue would apply to other non-standard dll hosts.
Can anyone recommend a better approach?

Richard.
richlm - 31 Mar 2006 16:12 GMT
Option 2 seems to work OK so I'll post some code snippets for the benefit of others.
Still if anyone has additional comments please post.

private static List<System.Configuration.Configuration> _configurations = null;

...

// check the default configuration

object config = ConfigurationManager.GetSection(sectionName);

if (config == null)

   {

   // check the alternative configurations

   if (_configurations == null)

       LoadConfigurations();

   foreach (System.Configuration.Configuration cfg in _configurations)

   {

       config = cfg.GetSection(sectionName);

       if (config != null)

           break;

   }

}

...

private static void LoadConfigurations()

{

   _configurations = new List<System.Configuration.Configuration>();

   string path = Assembly.GetCallingAssembly().CodeBase;

   string folder = Path.GetDirectoryName(path);

   string processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;

   ExeConfigurationFileMap map = new ExeConfigurationFileMap();

   // check for [host-exe].config in the same folder as the calling assembly

   string configFile = Path.Combine(folder, processName + ".exe.config");

   if (File.Exists(configFile))

   {

       map.ExeConfigFilename = configFile;

       _configurations.Add(ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None));

   }

   // check for mycompanyname.config in the same folder as the calling assembly

   configFile = Path.Combine(folder, "mycompanyname.config");

   if (File.Exists(configFile))

   {

       map.ExeConfigFilename = configFile;

       _configurations.Add(ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None));

   }

}

> I'm developing a snap-in for MMC 3.0 using .Net framework 2.0 and the new
> MMC class library.
[quoted text clipped - 15 lines]
>
> Richard.
Eric Voskuil (MVP) - 01 Apr 2006 20:18 GMT
richlm,

See:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/managedMMC_MRef
/html/P_Microsoft_ManagementConsole_SnapInSettingsAttribute_ConfigurationFile.as
p?frame=true


Eric
 Option 2 seems to work OK so I'll post some code snippets for the benefit of others.
 Still if anyone has additional comments please post.

 private static List<System.Configuration.Configuration> _configurations = null;

 ...

 // check the default configuration

 object config = ConfigurationManager.GetSection(sectionName);

 if (config == null)

     {

     // check the alternative configurations

     if (_configurations == null)

         LoadConfigurations();

     foreach (System.Configuration.Configuration cfg in _configurations)

     {

         config = cfg.GetSection(sectionName);

         if (config != null)

             break;

     }

  }

 ...

 private static void LoadConfigurations()

 {

     _configurations = new List<System.Configuration.Configuration>();

     string path = Assembly.GetCallingAssembly().CodeBase;

     string folder = Path.GetDirectoryName(path);

     string processName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;

     ExeConfigurationFileMap map = new ExeConfigurationFileMap();

     // check for [host-exe].config in the same folder as the calling assembly

     string configFile = Path.Combine(folder, processName + ".exe.config");

     if (File.Exists(configFile))

     {

         map.ExeConfigFilename = configFile;

         _configurations.Add(ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None));

     }

     // check for mycompanyname.config in the same folder as the calling assembly

     configFile = Path.Combine(folder, "mycompanyname.config");

     if (File.Exists(configFile))

     {

         map.ExeConfigFilename = configFile;

         _configurations.Add(ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None));

     }

 }

 "richlm" <richlm@nospam.nospam> wrote in message news:eremtsLVGHA.4792@TK2MSFTNGP14.phx.gbl...
 > I'm developing a snap-in for MMC 3.0 using .Net framework 2.0 and the new
 > MMC class library.
 >
 > I need to store some configuration settings, ideally in a .config file
 > associated with my snap-in dll.
 >
 > A couple of possible solutions:
 > 1. Deploy an mmc.exe.config to %windir%\System32 - not really a workable
 > solution.
 >
 > 2. Open a configuration file explicitly as a "Configuration" instance using
 > e.g. ConfigurationManager.OpenMappedExeConfiguration. That's almost OK - but
 > the config file either needs to be in System32 or we have to hard-code a
 > path (or maybe get the path from Assembly.CodeBase).
 >
 > The same issue would apply to other non-standard dll hosts.
 > Can anyone recommend a better approach?
 >
 > Richard.
 >
 >

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.